0

I have a server at www.example.com running a PHP-made webpage served by Apache, this page is listening to port 80.

Now I want to serve my Node.JS on the domain www.example2.com. Both pages should be on the same server, the Node.JS app should be running on port 3000. How do I achieve this?

From other answers and blog posts (like this one: http://garr.me/blog/running-node-js-and-apache-together-using-mod_proxy/) I have learnt that I can create a ReverseProxy to redirect www.example.com/app to my app, however this is not the intended behavior. What I want is this new domain www.example2.com to go the server's ip address at port 3000.

Side question: This question might sound stupid but, can't I redirect the whole domain to the server's IP address at port 3000 from the domain name configuration at GoDaddy/Route53???

Thanks.

  • Create new virtual host and configure mod_proxy to pass all requests to node – Alexey Ten Dec 24 '14 at 6:50
4

I solved it. The page on the original question gives a good advice however it doesn't seems complete. To achieve this configuration do the following:

-Locate the file httpd.conf on your Apache folders (usually on apache2/conf).

-Add the following lines to the end:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName example2.com
  ServerAlias www.example2.com
  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/
</VirtualHost>

-Change the placeholder "example2" for your actual domain name (example2 is the domain name on the original question)

-Restart apache.

Note that you might want to tidy the code a little bit by moving the LoadModule lines to where the modules are actually loaded.

1

Now I want to serve my Node.JS on the domain www.example2.com. Both pages should be on the same server, the Node.JS app should be running on port 3000. How do I achieve this?

There are two steps.

  1. You need to create a virtual host in apache listening on IP:3000 and responding to requests for example2.com
  2. You need mod_proxy running to take requests for example2.com on port 80 and push them to IP:3000 where the virtual host is listening.

can't I redirect the whole domain to the server's IP address at port 3000 from the domain name configuration at GoDaddy/Route53???

No. You are not familiar with the various network layers, including where DNS, TCP, IP, and everything in between fits into place. Might I suggest reading a little book no the topic. Twice. It will hold you on good stead. =)

  • Thanks. I already solved it by playing a little with the httpd.conf. If you have some pieces of code it would be great to enrich the steps 1 and 2 to have a clearer view on how to achieve that. I'm still not sure that the way that I found (posted now as an answer) is the best answer... – adelriosantiago Dec 24 '14 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.