请教一下关于nginx反代websocket增加ssl的问题

pigwing
  • 1
新手上路,请多包涵

目前我使用了nginx反代我内网的一台提供websocket的服务器,配置如下

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
        }
        server {

    listen 443 ssl;
    ssl on;
    ssl_certificate       certs/xxx.pem;
        ssl_certificate_key   certs/xxx.key;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        ssl_verify_client off;
    

    server_name xxx.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        proxy_pass   http://xxx:8888;
        proxy_http_version 1.1; 
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection         $connection_upgrade;
           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_connect_timeout 60;
           proxy_read_timeout 600;
          proxy_send_timeout 600;
            
    }


}
}

发现一个问题是当我主动关闭websocket连接的时候,浏览器会报

WebSocket connection to 'wss://xxx' failed: Invalid frame header

这个异常非常奇怪,但是我取消wss使用ws的时候一切都正常,所以排除是我程序的问题.请教一下同学们,这大概是一个什么问题呢.

评论
阅读 636
1 个回答

X-Forwarded-ProtoX-Forwarded-Port 这两个头也在代理里传一下再看看。

撰写回答

登录后参与交流、获取后续更新提醒

宣传栏