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
---------------------
作者:赵丶先森
来源:CSDN
原文:https://blog.csdn.net/weixin_37264997/article/details/80341911
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/larry-luo/p/10488559.html