3

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!

1 Answer 1

9

It was really easy, it worked by putting a "slash" at the end of the urls:

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";
}

I was quite sure to have already tried that way, but seems like I was wrong! :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.