This page is about some tech keys for making websocket with Tomcat + Nginx work
WebSocket is already in CLOSING or CLOSED state.
Websocket cannot be connected, or closed unexpectedly after connected.
Note that upstream server unhandled exceptions can close a websocket. For debugging, you may test a websocket and print closereason when onclose.
Configure websocket endpoint in tomcat.
Write this in your Nginx configuration file of your website
location /<Your-End-Point>/ {
proxy_pass "http://<your-domain>:<tomcat-port>/<Your-End-Point>";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
#Expire time, optional but recommended.
proxy_connect_timeout 1d;
proxy_send_timeout 1d;
proxy_read_timeout 1d;
}
Restart tomcat, websocket should work now.