KBEngine使用Nginx反向代理支持WSS协议
目前很多H5的游戏需要用https和wss协议,特别是腾讯微信小游戏必须走https协议,而https协议的网站必须用websocket的wss协议才能实现连接.
具体Nginx怎么实现的websocket就不再具体介绍,网络上有很多相关的文章 .
这里只给出我的nginx配置:
#----------KBEngine登录(loginapp)服务器-----------------
#这个下面有用到,xxx可以根据需要改掉
upstream stream_xxx_loginapp{
server 127.0.0.1:20013;
}
server {
listen 30013;
server_name example.loginapp;#根据自己的域名改
ssl on;
ssl_certificate /app/nginx1.14.0/certificate/xxx.crt;#ssl证书
ssl_certificate_key /app/nginx1.14.0/certificate/xxx.key;#ssl证书key
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv3;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
error_log /data/logs/nginx/error.xxx.log;#错误信息日志
access_log /data/logs/nginx/xxx.log main;#访问日志
location / {
proxy_pass http://stream_xxx_loginapp;#上面的upstream有注释,和上面保持一致
proxy_read_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
#----------KBEngine登录(baseapp)服务器-----------------
upstream stream_xxx_baseapp{
server 127.0.0.1:20015;
}
server {
listen 30015;
server_name example.baseapp;#根据自己的域名改
ssl on;
ssl_certificate /app/nginx1.14.0/certificate/xxx.crt;
ssl_certificate_key /app/nginx1.14.0/certificate/xxx.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv3;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
error_log /data/logs/nginx/error.proxy.fly.baseapp.log;
access_log /data/logs/nginx/proxy.fly.baseapp.log main;
location / {
proxy_pass http://stream_xxx_baseapp;
proxy_read_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}