前言
nginx支持ws协议的配置
配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream BackendIotWs {
server 10.0.0.110:7004 weight=1;
}
server {
listen 80;
server_name ws.iot.com;
location / {
try_files $uri $uri/ /index.html last;
root "/usr/local/openresty/nginx/std/manage/";
index index.html index.htm;
}
location /ws/iot {
proxy_pass http://BackendIotWs
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 3600s;
proxy_connect_timeout 86400;
proxy_ignore_client_abort on;
}
}
测试
- 访问地址:ws://ws.iot.com/ws/iot
- 测试地址:http://coolaf.com/tool/chattest,测试正常结果,如下所示
结语
测试ws访问的地址
|