在nginx/config/nginx.conf中添加下面配置
map $http_upgrade $connection_upgrade{
default upgrade;
'' close;
}
upstream web{
server 域名;
}
upstream websocket{
server X.x.x.x:8888;
}
upstream websocket1{
server x.x.x.x:7777;
}
server{
listen 443;
server_name 域名;
charset utf-8;
ssl on;
ssl_certificate 證書;
ssl_certificate_key ;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_protocols TLSV1.1 TLSV1.2 SSLv2 SSLv3;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
#websocket代理地址
location /wss {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /jz {
proxy_pass http://websocket1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
#原來的https功能代理回原來的地址
location /{
proxy_pass http://web;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin *;
}
}
在nginx/sbin/中執(zhí)行
./nginx -c nginx.conf
./nginx -s reload
網站后端使用workman監(jiān)聽websocket 端口
可以監(jiān)聽不同的端口