Nginx SSL反向代理不适用于websocket

时间:2020-08-01 09:53:58

标签: nginx websocket reverse-proxy

我具有以下配置:

server {
listen 443 ssl;
listen [::]:443 ssl;

server_name mydomain.com;

ssl_certificate /usr/syno/etc/certificate/ReverseProxy/baac8259-962a-4d45-a265-bf747f5f007d/fullchain.pem;

ssl_certificate_key /usr/syno/etc/certificate/ReverseProxy/baac8259-962a-4d45-a265-bf747f5f007d/privkey.pem;

location / {

    proxy_connect_timeout 60;

    proxy_read_timeout 60;

    proxy_send_timeout 60;

    proxy_intercept_errors off;

    proxy_http_version 1.1;

    proxy_set_header        X-Forwarded-Proto            \"http\";

    proxy_set_header        X-ProxyScheme            \"http\";

    proxy_set_header        Upgrade            $http_upgrade;

    proxy_set_header        Connection            $connection_upgrade;

    proxy_set_header        Host            $http_host;

    proxy_set_header        X-Real-IP            $remote_addr;

    proxy_set_header        X-Forwarded-For            $proxy_add_x_forwarded_for;

    proxy_pass http://192.168.1.4:8090;

   }
}

我只想在前端应用SSL,并在后端使用基本http。

此配置应该可以正常运行,但无法打开websocket网站,向我显示此错误:

WebSocket connection to 'wss://mydomain.com:80/' failed: Error in connection establishment: 
net::ERR_SSL_PROTOCOL_ERROR

在Web应用程序的javascript文件中浏览,我看到的是:

window.websocket = (document.location.protocol == "https:") ? new WebSocket('wss://'+document.location.hostname+":"+window.jsonPort) : new WebSocket('ws://'+document.location.hostname+":"+window.jsonPort);

问题是我真的不明白为什么应用程序会将方案检测为https?由于我明确尝试使其显示为http。

1 个答案:

答案 0 :(得分:0)

此问题特定于我要转发到的应用程序。我现在已经确定并纠正了该应用程序中的问题,因此可以解决。