Question

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

Posted December 5, 2014 9.5k 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:
app1.domain.com -> /home/myuser/www/app1 -> PHP
app2.domain.com -> /home/myuser/www/app2 -> NODE
app2.domain.com -> /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 {
    server_name app1.domain.com;
    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 {
    server_name app1.domain.com;
    root /home/myuser/www/app1;
}

server {
    server_name app2.domain.com;
    root /home/myuser/www/app2;
}

server {
    server_name app3.domain.com;
    root /home/myuser/www/app3;
}

Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

you have to use nginx reverse proxy for nodejs app

server {
    listen 80;
    server_name app2.domain.com;
    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
https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab

by Christian Fei
This is our tutorial on hosting multiple Node.js apps on a single VPS with nginx, forever, and crontab.
Submit an Answer