0

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.