Nginx SSL 反向代理不适用于 websocket

Nginx SSL reverse proxy doesn't work with websocket

我有这样的配置:

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);

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

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