我是前端Web应用程序开发的新手。我收到的WebSocket连接失败如下:
WebSocket connection to 'ws://127.0.0.1:7983/websocket/' failed: Error in connection establishment: net::ERR_EMPTY_RESPONSE
我查看了这个WebSocket错误,发现转到了以下页面。
Shiny & RStudio Server: "Error during WebSocket handshake: Unexpected response code: 404"
WebSocket connection failed with nginx, nodejs and socket.io
Rstudio and shiny server proxy setting
然后我在Windows 7机器上下载了nginx,并在nginx.conf中添加了以下注释,保存并执行了runApp()。
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
proxy_pass http://localhost:7983;
proxy_redirect http://localhost:7983/ $scheme://$host/rstudio/;
}
这似乎没有解决问题。我想我可能需要在nginx.conf文件中添加一些额外的东西,或者将它放在特定的目录中。请协助。谢谢!
编辑nginx.conf脚本如下:
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:5127;
proxy_redirect http://127.0.0.1:5127/ $scheme://$host/rstudio/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
答案 0 :(得分:9)
我想你忘记了使用Nginx的WebSockets所需的三行精彩代码:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
将它们添加到您的location /rstudio/ {}
此外,默认情况下,连接将在30秒后关闭而没有活动。 解决方法:
proxy_read_timeout 999999999;
WebSockets需要HTTP 1.1协议才能工作。这三行使浏览器使用HTTP 1.1连接到网站,并将您的服务器代理为HTTP 1.1。
如果您想了解更多信息,here可能会有帮助的博文。
答案 1 :(得分:4)
在这个问题上挣扎了好几天后,我发现问题是防火墙阻止了websocket的工作。我安装了Pandas Antivirus并在其中启用了防火墙。当我关闭并使用Windows防火墙并打开该传入端口时,它开始工作。
希望有所帮助