利用nginx代理wss【通讯原理及流程】
- wss协议实际是websocket+SSL,就是在websocket协议上加入SSL层,类似https(http+SSL)。
- 客户端发起wss连接连到nginx
- nginx将wss协议的数据转换成ws协议数据并转发到Workerman的websocket协议端口
- Workerman收到数据后做业务逻辑处理
- Workerman给客户端发送消息时,则是相反的过程,数据经过nginx/转换成wss协议然后发给客户端
server {
listen 80;
listen 443 ssl http2;
server_name example.com;
location / {
# 代理转发地址
proxy_pass http://127.0.0.1:8080;
# 超时设置
proxy_read_timeout 3600s;
# 启用支持websocket连接,重要的是这两行,它表明是websocket连接进入的时候,进行一个连接升级将http连接变成websocket的连接。
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 强制https
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
# SSL证书配置
ssl_certificate /www/server/panel/vhost/cert/example.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/example.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
}
标签:websocket,ssl,server,nginx,wss,EECDH,连接
From: https://www.cnblogs.com/oldweipro/p/17055318.html