apache - 无法启动传输“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/
解决方案
我解决了这个问题,把下面的代码放在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;
}
推荐阅读
- java - 问题:由于缺少 ant-contrib-1.0b3.jar,无法创建任务或键入 thrift
- java - 使用 slick 和 hikariCP 的 SSL 连接
- angular - Angular 2 项目对 git 子模块的依赖
- snowflake-cloud-data-platform - 在雪花中放置多个仓库的最佳方法?
- sap - SAP Business Objects Webi 中有多个图表?
- javascript - Mongoose 对象在填充时返回未定义
- .net - 与 Azure 逻辑应用的连接已被远程主机关闭
- javascript - 在js中更改二维数组行的字体颜色
- maven - 强制 maven 始终从目标文件夹中获取工件
- java - 在非 Spring Boot 应用程序中从外部源(JAR 文件外部)加载 Thymeleaf 模板