Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny Websocket Error

I'm new to front end web app development. I'm receiving a WebSocket connection failure as follows:

WebSocket connection to 'ws://127.0.0.1:7983/websocket/' failed: Error in connection establishment: net::ERR_EMPTY_RESPONSE

I looked up this WebSocket error and found diverted to the following pages.

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

I then downloaded nginx on my Windows 7 machine and added the following comment in nginx.conf, saved and executed runApp().

location /rstudio/ {
 rewrite ^/rstudio/(.*)$ /$1 break;
 proxy_pass http://localhost:7983;
 proxy_redirect http://localhost:7983/ $scheme://$host/rstudio/;
}

This didn't seem to solve the issue. I think I may need to add some extra stuff into the nginx.conf file or put it in a specific directory. Please assist. Thanks!

EDITED the nginx.conf script as follows:

        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";
    }
like image 328
Aks Avatar asked Apr 06 '15 23:04

Aks


2 Answers

After struggling on this same issue for some days I found that the problem was that the Firewall was preventing the websocket from working. I had Pandas Antivirus installed and Firewall was enabled in it. When I turned it off and used Windows firewall and opened that incoming port then it started working.

Hope it helps

like image 146
voidrus Avatar answered Nov 07 '22 00:11

voidrus


I think you forgot these three wonderful lines of code required to use WebSockets with Nginx:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

Add them to your location /rstudio/ {}

Also, by default the connection will be closed after 30 seconds without activity. Workaround:

proxy_read_timeout 999999999;

WebSockets need HTTP 1.1 protocol for working. These 3 lines make the browser connect to the website using HTTP 1.1, and proxy your server as HTTP 1.1.

If you want to know more, here's a blog post that might help.

like image 12
Gabriel Tomitsuka Avatar answered Nov 07 '22 02:11

Gabriel Tomitsuka