Question

How to run multiple node application with NGINX: same droplet same domain

I followed the tutorial here with node and NGINX. They work great. But, they all are running the node application from the root of the domain.

I have a number of small node apps and I want to be able to run them like:

http://mydomain/app1 http://mydomain/app2

where app1 may be localhost:9000 and app2 is localhost:9001 etc.

when I change my hosts-enabled file from location / to location /app1/

server {
    listen 0.0.0.0:80;
    server_name 192.241.223.202;
    access_log /var/log/nginx/ddApp.log;

    location /app1/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:9000;
        proxy_redirect off;
    }
}

my application is launched (node sends down the html document) but the browser can’t follow any of the links (load any resources …404’s).

This direct link can get the resouces:

http://192.241.223.202:9000/app/b7672478.app.js

but through the app1 path

http://192.241.223.202/app1/app/b7672478.app.js

NGINX just serves up the root html document.

Actually all requests to the app1 path produce the same response.

The NGINX docs just make my head hurt (as well as my pride).

Any help and direction would be great.

P:)


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Oh happy days! We are up with app1! … other than a couple of bootstrap fronts out of the bower component failing to pick up the app1 base … I’ll deal with it later. Also the <base> tag needs a trailing slash so for this baby it was:

<base href="/app1/">

THANK YOU SO MUCH!!!

I spent hours and hours trying to solve this same problem. Knowing those hours are wasted because I needed a trailing slash is heartbreaking, but so glad I found this post.

sorry … I’ve added morgan (I’m on Express 4) I only seem to get a Get / 304 with http://192.241.223.202/app1/ and then the broken app is displayed in the browser

Here is a session:

root@test:/var/log/upstart# service ddApp stop ddApp stop/waiting root@test:/var/log/upstart# service ddApp start ddApp start/running, process 7080 root@test:/var/log/upstart# tail ddApp.log -f league list GET /api/leagueList 304 160ms GET /api/leagueList 304 161ms GET / 304 157ms GET / 304 159ms GET / 304 164ms info - socket.io started loading league.controller Express server listening on 9000, in production mode db connection open GET / 304 181ms GET / 304 164ms <-- one of these for each refress of the browser at http://192…/app1