Home  >  Q&A  >  body text

nginx reverse generation websocket disconnected

PS: Official documents say that Nginx only supports websocket reverse proxy in versions after 1.3, so if you want to use the function that supports websocket, you must upgrade to versions after 1.3;

There is a problem. Every once in a while, the websocket is disconnected for 1-2 minutes. The service will be restarted or it will automatically recover after 2 minutes.
The service layer architecture is nginx reverse generation tomcat;

Skip the compilation and installation of nginx...

The websocket configuration is as follows:

http {
     ......

     #websocket 需要加下这个
     map $http_upgrade $connection_upgrade {
         default upgrade;
         '' close;
    }

     ......
}

server {
        ......


        location  ^~  /websocket {
        proxy_pass http://www.test.com;

        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        }

        ......
}
过去多啦不再A梦过去多啦不再A梦2712 days ago758

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 17:27:51

    The problem has been found, please post it;

    nginx.conf
    proxy_read_timeout 86400;

    include http://www.test.com
    keepalive 64;

    reply
    0
  • Cancelreply