Kandrat
Kandrat

Reputation: 474

Use nginx as proxy for websocket connection

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 ?

Upvotes: 4

Views: 1477

Answers (1)

CaiPeijun
CaiPeijun

Reputation: 96

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.

Upvotes: 8

Related Questions