nginx配置websocket代理 ws
时间: 2023-11-08 15:01:47 浏览: 137
Nginx反向代理Websocket
nginx配置websocket代理的方式有多种,根据提供的引用内容,可以使用以下两种方式来配置websocket代理:
方式一:
```nginx
server {
listen 9001;
server_name 192.168.1.219;
add_header Access-Control-Allow-Origin *;
location / {
proxy_pass http://192.168.1.219:5670;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1800s;
proxy_send_timeout 1800s;
proxy_read_timeout 1800s;
}
}
```
方式二:
```nginx
server {
listen 9000 ssl;
server_name telsip.svc.com 258.11.121.31;
ssl_certificate /etc/nginx/6723447__svc.com.pem;
ssl_certificate_key /etc/nginx/6723447__svc.com.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4 RSA: HIGH: MEDIUM: LOW: SSLv2: EXP;
ssl_prefer_server_ciphers on;
ssl_verify_client off;
add_header Access-Control-Allow-Origin *;
location / {
proxy_pass http://192.168.1.219:5670;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1800s;
proxy_send_timeout 1800s;
proxy_read_timeout 1800s;
}
}
```
以上两种方式分别在不同的server块中配置了websocket代理。方式一使用了非ssl监听端口9001,方式二使用了ssl监听端口9000,并配置了ssl证书。
阅读全文