Configuring multiple node servers using Nginx without subdomains

I searched everything, but did not find a single person who hosted several node sites on the same server without using subdomains. I want something like the following ...

website.com/app1 β†’ 127.0.0.1//000
website.com/app2 β†’ 127.0.0.1:9000

upstream node { server 127.0.0.1:3000; keepalive 64; } server { listen 80; server_name webaddress.com; root /var/www/trucks/; location /livereload { proxy_pass http://localhost:35729; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location /app1 { rewrite ^/app1/?(.*) /$1 break; 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_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:3000; root /var/www/trucks; } 

I even tried rewriting the request; however, this has no effect. If I remove / app 1, it works correctly. The closest I got is forwarding to several sites, but local local routes are not valid.

+6
source share
4 answers

I have a working setup as follows:

 server { listen 8080; server_name localhost; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; } location /api { proxy_pass http://localhost:3001; rewrite ^/api(.*) /$1 break; proxy_set_header Host $host; } } 
+1
source

Have you tried using the proxy_redirect directive instead of rewrite ? http://wiki.nginx.org/HttpProxyModule#proxy_redirect

0
source
0
source

the problem with your configuration is that you are simply using a proxy server to easily connect HTTP applications to the application proxy. No need to use rewriting. Here is the simplest configuration I could come up with:

 server { listen 80; index index.html index.htm; server_name _; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; location /node1 { proxy_pass http://localhost:8888; } location /node2 { proxy_pass http://localhost:9999; } } 

I recommend that you redraw the websockets-related documentation on nginx: http://nginx.org/en/docs/http/websocket.html

0
source

Source: https://habr.com/ru/post/958611/


All Articles