I have 2 NodeJS applications running locally on port 3000 and 3001. I'm trying to route to them individually by using my_ip/tilbudsfinneren for one of them, and my_ip/hms for the other one.
My sites-available file looks like this:
server {
listen 80;
listen [::]:80;
root /var/www/my_ip/html;
index index.html index.htm index.nginx-debian.html;
server_name my_ip www.my_ip;
location /tilbudsfinneren {
proxy_pass http://localhost:3000;
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 /hms {
proxy_pass http://localhost:3001;
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;
}
}
Whenever I try to reach my_ip/hms or my_ip/hms/ping it does not reach the NodeJS application, I get get "Cannot GET /hms". Is there an issue with my nginx configuration, or is there maybe something else wrong?
asked May 26, 2021 at 19:13
Asgeir
6971 gold badge11 silver badges23 bronze badges
1 Answer 1
If you want to serve both apps as reverse proxy you must use rewrite methods in both locations.
server {
listen 80;
index index.html index.htm index.nginx-debian.html;
location /tilbudsfinneren/ {
rewrite ^/tilbudsfinneren/(.*)$ /1ドル break;
proxy_pass http://localhost:3000;
#other config...
}
location /hms/ {
rewrite ^/hms/(.*)$ /1ドル break;
proxy_pass http://localhost:3001;
}
}
answered May 27, 2021 at 4:08
Daniel Mesa
5965 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js