Report this

What is the reason for this report?

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

Posted on December 5, 2014

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!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

This comment has been deleted

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

This comment has been deleted

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.