Websocket 302 (redirect) error

October 1, 2016 458 views
Nginx Sinatra Ubuntu

http://prntscr.com/coliya -Chrome
http://prntscr.com/coljez -Opera

NGINX
server {

listen 0.0.0.0:80;
listen 0.0.0.0:443 ssl;
root /usr/share/nginx/html;
index index.html index.htm;

ssl on;
sslcertificate /etc/ssl/certs/ssl-bundle.crt;
ssl
certificatekey /etc/ssl/private/budokai-onlinecom.key;
sslciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kED$
ssl
dhparam /etc/ssl/private/dhparmas.pem;
sslpreferserverciphers on;
ssl
protocols TLSv1 TLSv1.1 TLSv1.2;

if ($sslprotocol = "") {
rewrite ^ https://$host$request
uri? permanent;

}
largeclientheader_buffers 8 32k;
location / {

proxyhttpversion 1.1;

proxysetheader Accept-Encoding "";
proxysetheader X-Real-IP $remoteaddr;
proxy
setheader Host $host;
proxy
setheader X-Forwarded-For $proxyaddxforwardedfor;
proxy
setheader XFORWARDEDPROTO https;
proxy
setheader X-NginX-Proxy true;
proxy
buffers 8 32k;
proxybuffersize 64k;
proxysetheader Upgrade $httpupgrade;
proxy
setheader Connection "Upgrade";
proxy
readtimeout 86400;
proxy
pass http://budokai-online.com:8080 ;

}

The problem I'm having is that some computers and some browsers are being redirected when trying to get a connection to the websocket. When that 302 error shows up, the '/*' routes has been activated! This route redirects the user to the login page as you saw in the redirect response.The websocket upgrade request is turned into an ordinary http request somehow, somewhere! This seems to be where the problem is. What can be causing this?

1 Answer

You may need to update

if ($sslprotocol = "") {
rewrite ^ https://$host$requesturi? permanent;

}

to this

if ($https = "") {
rewrite ^ https://$host$requesturi? permanent;

}

I haven't seen the use of $sslprotocol before in this context and wasn't able to find anything through a google search.

Have another answer? Share your knowledge.