问题 闪亮的Websocket错误


我是前端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:“WebSocket握手期间出错:意外的响应代码:404” 

使用nginx,nodejs和socket.io,WebSocket连接失败

Rstudio和闪亮的服务器代理设置

然后我在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";
    }

2401
2018-04-06 23:15


起源

我的回答有用吗?如果是这样,请接受我的回答:P - Gabriel Tomitsuka


答案:


在这个问题上挣扎了好几天后,我发现问题是防火墙阻止了websocket的工作。我安装了Pandas Antivirus并启用了防火墙。当我关闭它并使用Windows防火墙并打开该传入端口然后它开始工作。

希望能帮助到你


4
2018-04-17 23:36





我想你忘记了使用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。

如果你想了解更多, 这里这是一篇可能有所帮助的博客文章。


6
2018-04-15 14:04



它仍然不适合我。这是我在nginx.conf中的内容(编辑了我的问题)。 nginx.conf应该有一个特定的目录吗?或者如何检查这是否与我的浏览器实际通信?谢谢! - Anuj
等待等待等待等待... WebSocket连接到'ws://127.0.0.1:7983 / websocket /'失败...请尝试'ws://127.0.0.1:7983 / rstudio / websocket /'。 - Gabriel Tomitsuka
我在conf文件中提到过location / rstudio。你到底在说什么? - Anuj
我的意思是WS被代理在/ rstudio路径下。 (抱歉这么久) - Gabriel Tomitsuka