Nginx configure websocket connection

Websocket used in the project, but unable to connect through Nginx, add nginx configuration

1. Add in the http block

         map $http_upgrade $connection_upgrade {
             default upgrade;
            '' close;
         }

2. Add in the localhost block

        # 启用支持websocket连接
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

Socket access address: ws://域名 /hcx/websocket/ 参数一/ 参数二

Such as:
Insert picture description here

3. Reload the nginx configuration file

./nginx -s  reload
  • Personal open source project (universal background management system) –> https://gitee.com/wslxm/spring-boot-plus2 , you can check it out if you like

  • This is the end of this article. If you find it useful, please like or pay attention to it. We will continue to update more content from time to time... Thank you for watching!

Guess you like

Origin blog.csdn.net/qq_41463655/article/details/108442235