How to setup a server with PHP and Node.js?

December 5, 2014 3k views

Hello, I'm new in DO and i'm trying to configure my server for deploy some apps.

I would like to set my DNS in my domain and redirect to my app in DO.
And another thing, an app can run Node or PHP.

For example: -> /home/myuser/www/app1 -> PHP -> /home/myuser/www/app2 -> NODE -> /home/myuser/www/app3 -> NODE

First, I installed PHP, Node and Nginx.

How can I modify the Nginx config file to make the redirects?

My Nginx file until now:

server {
    root /home/myuser/www/app1;

PS: At this time, if i try to enter in my droplet ip (104.XXX.77.XX), i see the app1 html.

I'm thinking of something like this:

server {
    root /home/myuser/www/app1;

server {
    root /home/myuser/www/app2;

server {
    root /home/myuser/www/app3;


3 Answers

you have to use nginx reverse proxy for nodejs app

server {
    listen 80;
    location / {
        proxy_pass http://localhost:{YOUR_NODEJS_PORT};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

or something

by Christian Fei
This is our tutorial on hosting multiple Node.js apps on a single VPS with nginx, forever, and crontab.
  • Thanks wiak.

    So, i have to create a config like yours every time that i create a new app with node?
    If i need to create like an for example, do i need to duplicate de server config?

  • yep, exactly the same for another node app if you want to run it under another domain/server
    there are other ways like doing it on a nameserver level but doing it in nginx is far faster and easier

  • my blog runs ghost nodejs reverse proxy'd with lighttpd

    and my lftp windows builds directory run on lighttpd+php

    same works with nginx, i just like lighttpd more and am more use to that

  • Thanks again wiak, i will try and then, i will post here if i need more help hehe

  • am on irc if you need me ;)

  • are there some channel or room to connect?

    its unofficial eh ;)
Have another answer? Share your knowledge.