首页 > 解决方案 > 无法启动传输“WebSockets”:null,Plesk Apache

问题描述

我有一个单页应用程序,这个应用程序是用 .net CORE + ReactJS 开发的。我设法在 centos 7 + plesk 面板上运行该应用程序。我在 Plesk 面板中进行了 Apache 设置,但 websocket 给出了错误。我该如何解决?

应用程序运行时出现以下错误。

WebSocket connection to 'wss://mydomaindomain.xyz/hubCon?id=epgy-kgVtR9HU7kxgErVAQ&access_token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9...................

[2021-07-26T15:18:08.636Z] Error: Failed to start the transport 'WebSockets': null

这是 Plesk 面板中的 Apache 设置部分。

Header set Access-Control-Allow-Origin "http://mydomaindomain.xyz"
Header set Access-Control-Allow-Headers "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization, Content-Disposition"
Header set Access-Control-Allow-Methods "*"
Header set Access-Control-Allow-Credentials "true"

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/

标签: apacheasp.net-corewebsocketsignalrplesk

解决方案


我解决了这个问题,把下面的代码放在plesk面板的apache & nginx设置下的nginx部分,问题就解决了。

location ^~ /yourSocketName {
    
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header 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_set_header X-Frame-Options SAMEORIGIN;
        proxy_pass http://127.0.0.1:5000;
    }

推荐阅读