Nginx 支持websocket的配置

Nginx 支持websocket的配置

server {
      listen   80;
      server_name 域名;
      location / {
        proxy_pass   http://127.0.0.1:8080/; // 代理转发地址
     proxy_http_version 1.1;
        proxy_read_timeout   3600s; // 超时设置
        // 启用支持websocket连接
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
      }
      location /upload { // 静态资源地址
            root   /mnt/resources;        
      }
}

重要的是这两行,它表明是websocket连接进入的时候,进行一个连接升级将http连接变成websocket的连接。

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";


proxy_read_timeout; 表明连接成功以后等待服务器响应的时候,如果不配置默认为60s;

proxy_http_version 1.1; 表明使用http版本为1.1 

 

转载于:https://blog.csdn.net/weixin_37264997/article/details/80341911

 

posted @ 2021-09-17 17:52  西瓜君~  阅读(367)  评论(0编辑  收藏  举报