Question

I own a Debian server with a single IP address, which I use for all my personal projects. What I want to do is serve both my Wordpress and my Node.js apps from that same server if possible, using different internet domains for each app

For example

  • www.myblog.org:80 should serve wordpress/index.php
  • my_app.com:80 should serve node instance at localhost:3000
  • my_other_node_app.com:80 should serve node instance at localhost:3001 etc...

Is this thing possible somehow? I don't mind stop using apache if this is what it takes

Was it helpful?

Solution 2

You can serve on multiple domains using a reverse proxy server, like nginx.

Check out this question here: Nginx Different Domains on Same IP

But the basic idea is one server actually listens on port 80, and it handles sending the request to the right app server (php, node, etc) on your machine serving internally (localhost:8000).

It's not technically very hard to do, but getting used to configuring a new piece of software like nginx can be a little challenging. Definitely definitely doable though!

OTHER TIPS

Only one piece of software can listen on a given port of a given network interface.

If you had, for example, two ethernet adaptors, with different IP addresses, then you could configure your Node server to listen on port 80 on one of them and your Apache server to listen to port 80 on the other one, then set up DNS to point different domains at different ip addresses.

If you only have one ip address, then you would have to run the servers on different ports.

You could run Apache on port 80 and then use it to proxy requests to node.

This is definitely possible by using a webserver or proxy. The most common tool would be Nginx here, since it's both a webserver and a reserve proxy. You could then let Nginx listen to port 80 and point one domain to a PHP document root, and the other domain directly to the Node webserver which would run on port 8000 for example.

Another option would be to use HAProxy and a separate webserver for PHP. HAProxy is extremely fast, like Nginx. It's a bit more lowlevel making proxying websockets possible if you'd ever decide to run a loadbalancer. For now it doesn't really matter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top