I guess that the answer to my question will be very easy, but unfortunately I've not been able to figure out by myself!
I have Nginx running on Server A (192.168.1.1) acting as a reverse proxy for a WebSocket server on Server B (192.168.1.2). This last server is listening on port 1234 and has 2 paths, so we can connect to the following addresses:
ws://192.168.1.2:1234/path1
ws://192.168.1.2:1234/path2
I've been able to successfully connect to Path1 through the proxy (ws://192.168.1.1/websocket/path1) by adding the following configuration:
location /websocket/path1 {
proxy_pass http://192.168.1.2:1234/path1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Now I would like to make it general enough to match also the second path (instead of creating a similar rule for path2), I tried something like:
location /websocket {
proxy_pass http://192.168.1.2:1234;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
But in this way I can't reach the WebSocket.
Do you have any idea about what's wrong?
Thank you very much for your time!