1

Nginx is used as reverse proxy in front of a Node server. The Node server has one path (/ws) where WebSockets are used, this path needs special settings. /ws is not a directory, therefore a request to it must not have a trailing slash. What's the correct way to do configure this? The following configuration does not work, but shows what is intended.

location /service/ {
  proxy_read_timeout  30s;
  proxy_pass        http://service:8080/;

  # not working, requests are sent to http://service:8080/service/ws
  # instead http://service:8080/ws
  location /service/ws {  
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout  36000s;
  }
}
1

You are currently using a nested location, and I am not sure how proxy_pass is inherited by the inner block. You could try two independent location blocks with an explicit proxy_pass in each block:

location /service/ {
    proxy_read_timeout  30s;
    proxy_pass        http://service:8080/;
}
location /service/ws {  
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout  36000s;

    proxy_pass        http://service:8080/ws;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.