I am attempting to run two node.js applications from the same droplet, off the same url. I am serving the first app from http://finleywill.com, and would like to serve the second app from http://finleywill.com/todo.
I am running nginx on the server.
The first app, my portfolio page, listens to port 5000.
The second app, a to-do list, listens to port 8888.
/etc/nginx/sites-available/finleywill.com is as following:
server { listen 80; listen [::]:80;
root /var/www/finleywill.com/html;
index index.html index.htm index.nginx-debian.html;
server_name finleywill.com www.finleywill.com;
access_log /root/source/access.log;
error_log /root/source/error.log;
location / {
proxy_pass http://localhost:5000;
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;
}
location /todo {
proxy_pass http://localhost:8888;
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;
}
}
I use PM2 to run the apps as system processes
App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
app │ 0 │ 1.0.0 │ fork │ 27064 │ online │ 0 │ 72m │ 0% │ 55.5 MB │ root │ disabled │ app-todo │ 1 │ 1.0.0 │ fork │ 27156 │ online │ 0 │ 40m │ 0% │ 37.0 MB │ root │ disabled │
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!
Accepted Answer
I figured it out with help from a friend!
…as per https://serverfault.com/questions/650117/serving-multiple-proxy-endpoints-under-location-in-nginx
I changed /etc/nginx/sites-available/finleywill.com to the following:
server { listen 80; listen [::]:80;
root /var/www/finleywill.com/html;
index index.html index.htm index.nginx-debian.html;
server_name finleywill.com www.finleywill.com;
access_log /root/source/access.log;
error_log /root/source/error.log;
location / {
proxy_pass http://localhost:5000;
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;
}
(LINE BELOW HAS CHANGED)
location ^~ /todo/ {
proxy_pass http://localhost:8888/;
}
}
I have configured as same as above, but the page loading
server {
listen 443 ssl http2;
listen [::]:443 ssl;
include snippets/ssl-cert.conf;
include snippets/ssl-params.conf;
server_name dev.pm-lucida.com www.dev.pm-lucida.com;
error_log /var/log/nginx/complus.error.log;
access_log /var/log/nginx/complus.access.log;
# client_max_body_size 4M;
location / {
rewrite ^/(.*) /$1 break;
proxy_ignore_client_abort on;
proxy_pass http://13.234.214.144:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 4M;
}
location ^~/Charac/ {
proxy_pass http://13.234.214.144:3001/;
}
}
server {
listen 80;
listen [::]:80;
server_name dev.pm-lucida.com;
return 302 https://$server_name$request_uri;
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.