发布:2024/3/19 16:18:47作者:管理员 来源:本站 浏览次数:773
1. 使用Nginx代理ws
server {
listen 8086; # 监听8086端口
server_name 192.168.1.123; #也可以是域名
add_header Access-Control-Allow-Origin *;
location / {
#添加wensocket代理的目标服务器
proxy_pass http://192.168.1.3:8888;
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;
}
}
2.使用Nginx代理wss
说明:如果是内网环境使用,可以手动创建证书使用,如果是公网环境,则必须为公网域名证书或ip证书,使用域名可以去阿里创建免费证书并下载就可以了。
server {
listen 9006 ssl; # 监听9006 端口
server_name 自己的域名.com ;
ssl_certificate /etc/nginx/xxx.com.pem;
ssl_certificate_key /etc/nginx/xxx.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 / {
#添加wensocket代理
proxy_pass http://192.168.1.3:8888; # websocket服务器。不用管 ws://
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;
}
}
3.在线测试工具
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4