4

How do I use nginx as proxy for a websocket ? If I need to connect to socketSite.com:port from clientSite.com( javascript) And I won't to show user's link "socketSite.com:port "

Can I use nginx proxy for redirecting requests from/to websocket server ?

1 Answer 1

8

Absolutely, you can! Use the following configuration:

location /myHandler{
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header HOST $host;
    proxy_set_header X_Forwarded_For $remote_addr;
    proxy_pass http://localhost:8880;
    proxy_redirect default;
    client_max_body_size 1000m;
} 

I use spring websocket. /myHandler is my URL to create the websocket connection, http://localhost:8880; is my Tomcat server address. Nginx server and Tomcat are running on the same machine.

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.