【问题标题】:Shiny Websocket Error闪亮的 Websocket 错误
【发布时间】:2015-06-11 10:29:13
【问题描述】:

我是前端 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";
    }

【问题讨论】:

    标签: nginx websocket shiny rstudio


    【解决方案1】:

    我想你忘记了在 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 协议才能工作。这 3 行使浏览器使用 HTTP 1.1 连接到网站,并将您的服务器代理为 HTTP 1.1。

    如果您想了解更多信息,here 的博文可能会有所帮助。

    【讨论】:

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

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2016-01-11
      • 2017-07-06
      相关资源
      最近更新 更多