您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Nginx支持websocket怎么配置

2026/1/29 14:06:33发布28次查看
一、对wss与nginx代理wss的理解:1、wss协议实际是websocket+ssl,就是在websocket协议上加入ssl层,类似https(http+ssl)。
2、利用nginx代理wss【通讯原理及流程】
客户端发起wss连接连到nginx
nginx将wss协议的数据转发到workerman的websocket协议端口,同时将其转换成ws协议数据
workerman收到数据后做业务逻辑处理
workerman给客户端发送消息时,则是相反的过程,数据经过nginx/转换成wss协议然后发给客户端
二、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  
以上就是nginx支持websocket怎么配置的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product