rstudio / shiny-server

Host Shiny applications over the web.
https://rstudio.com/shiny/server
Other
712 stars 290 forks source link

Web Socket error #118

Open PilotGtec opened 9 years ago

PilotGtec commented 9 years ago

Hi, I just deployed my app on an amazon server and using Nginx. I am getting the following error

WebSocket connection to 'ws://webaddress.here/__sockjs__/613/2_g_1rfa/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

I can't seem to find any solution online. When I run the app on my local machine, everything runs smoothly.

Below is the sessionInfo().

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googleVis_0.5.7 ggplot2_1.0.0   shiny_0.11.1   

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     grid_3.1.1       gtable_0.1.2     htmltools_0.2.6  httpuv_1.3.2    
 [7] MASS_7.3-33      mime_0.2         munsell_0.4.2    plyr_1.8.1       proto_0.3-10     R6_2.0.1        
[13] Rcpp_0.11.5      reshape2_1.4     RJSONIO_1.3-0    scales_0.2.4     stringr_0.6.2    tools_3.1.1     
[19] xtable_1.7-4  

Would appreciate any suggestion on how I should attack and troubleshoot the problem.

Thanks.

Vladicon commented 9 years ago

The addition of +marked lines in /etc/nginx/conf.d/your.conf

location /rshiny/ {
  rewrite ^/rshiny/(.*)$ /$1 break;
  proxy_pass http://127.0.0.1:3838;
  proxy_redirect http://127.0.0.1:3838/ $scheme://$host/rshiny/;
+         proxy_http_version 1.1;
+         proxy_set_header Upgrade $http_upgrade;
+         proxy_set_header Connection $connection_upgrade;
}

and in /etc/nginx/nginx.conf

http {
+    proxy_read_timeout 950s;
+    map $http_upgrade $connection_upgrade {
+        default upgrade;
+        ''      close;
+    }
}

and the latest nginx solved the problem for me.

PilotGtec commented 9 years ago

Thank you, @Vladicon. I just implemented and added those three lines in the conf file, but still no dice.

Vladicon commented 9 years ago

Did you update nginx? Try to use version 1.9.1 from http://nginx.org/en/linux_packages.html#stable

WebSockets are well supported in the latest nginx versions.

Personally I don't use https, but if you do, then WebSockets address should start with wss://

PilotGtec commented 9 years ago

@Vladicon I tried the exact steps you suggested again and it's working now. Thanks!

trestletech commented 9 years ago

Was this causing connection problems for your application? Or just the spurious log message in the console?

The connection library we use (SockJS) prefers WebSockets but if you're unable to make a connection (as in your case), it has a variety of other protocols to which it can fallback, so it is safe to ignore that message if you so desired. If you know that you were behind a proxy that didn't support WebSockets, you could even disable them on the server so that you wouldn't see that message.

dileepgogula commented 8 years ago

I am very new to R and Shiny-server as well. I have installed the shiny-server and tried to run an example app from R-Studio but I am facing the same issue now. WebSocket connection to 'ws://...:7072/websocket/' failed: Error during WebSocket handshake: Unexpected response code: 503. I can only see the range filter but chart is not coming up. Where as i can see the chart and range filter properly in the default app that starts with shiny-server

The requested url from shiny-server default app is ws://...:7071/sample-apps/hello/sockjs/n=QaJOCCahR3pxU0zwzz/775/am8akd7b/websocket

where as the requested url from the app started from R-Studio is ws://...:7072/websocket/

I started the app in R-studio using the following command runExample("01_hello",port = 7072,host = getOption("shiny.host", "IP of the machine"))

AlexandraLouise commented 7 years ago

Thanks @Vladicon I used your step and it also worked :)