1

I have a node app already deployed on ec2 that redirects port 80 to 3000 using:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Now I want to add a Wordpress blog in a subfolder mydomain.com/blog. Must I use apache's ProxyPass as explained here? Won't it slow down node.js?

The example in the link also seems to be more suitable for cases where one wants to add node to apache and not the other way around..because of the URL distinction (/node) and port 8000, or it can fit both cases? Is there any other way to allow node and apache work on the same server? Also, how should the ports be managed?

Community
  • 1
  • 1
Omer Greenwald
  • 758
  • 7
  • 20

1 Answers1

6

I would suggest that you re-think your server architecture a bit. Here is what I would recommend.

Use Nginx server since its lightweight, free, and can run both PHP and NodeJS applications.

You will need to install Nginx's PHP module to make the PHP code work and you can also setup Nginx to proxy requests to your NodeJS application.

All this can be achieved by simply installing Nginx and configuring it using the many guides available online.

Updated on March 11, 2015

Here are the links to get these set up:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04

https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab

Noman Ur Rehman
  • 6,707
  • 3
  • 24
  • 39
  • That's an idea, but it's too broad for me because as I stated in the question, I'm a newbie in server configurations. I'm not sure about the actual flow. Can you link to a tutorial on how to proxy requests from nginx to nodejs? – Omer Greenwald Mar 11 '15 at 13:27
  • Thanks, that helps in nginx configuration for node but I'm not sure how to manage the ports for both nodejs app and the WP blog from there. – Omer Greenwald Mar 11 '15 at 13:39
  • @user3800705 Nginx will be serving Wordpress directly since it will be running on port 80. All you need to do is configure certain urls to be proxied to your NodeJS app running on, say port 3000. I have one more link to the answer. – Noman Ur Rehman Mar 11 '15 at 13:47
  • This line in the link you added proxy_pass http://localhost:{YOUR_PORT}; means that (assuming I replace localhost with mydomain.com), if the user enters mydomain.com and the node server is set to node 3000, it will be redirected as with the peice of code I have in my question? – Omer Greenwald Mar 11 '15 at 13:52
  • It's clearer now. thanks. I will try that configuration – Omer Greenwald Mar 11 '15 at 13:56
  • So you say the wp doesn't need nginx configuration. How do I tell nginx to direct all urls that don't contain "/blog" to port 3000? the node app is not SPA, it has multiple urls – Omer Greenwald Mar 11 '15 at 13:59