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";
}
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With