Tornado websockets with nginx reverse proxy

563 views
Skip to first unread message

Roman

unread,
Dec 27, 2016, 11:59:58 AM12/27/16
to Tornado Web Server
Dear,

I know, that this doesn't fully belong here, but I hope that you can help me.

I'm training to use nginx reverse proxy to redirect websockets to tornado server...

Tornado websocket handler works properly... But trough nginx, it changes ws:// to http:// with GET request

I have read this "how-to"  http://nginx.org/en/docs/http/websocket.html and some other "Q&A" but it still not works... 



map $http_upgrade $connection_upgrade {
       
default upgrade;
       
'' close;
}


server
{
    listen
5252;


    location
/ws {
        proxy_pass http
://127.0.0.1:10001;
        proxy_http_version
1.1;
        proxy_set_header
Upgrade $http_upgrade;
        proxy_set_header
Connection "upgrade";
        proxy_read_timeout
86400;
   
}
   

    . . .

}



From tornado I recieve:
WARNING:tornado.access:403 GET /ws/ (127.0.0.1) 0.38ms


With HTTP/GET method it works well. 


Thank you so much for all answers,
and have a nice day!
Roman

TaoBeier

unread,
Dec 28, 2016, 7:03:02 AM12/28/16
to Tornado Web Server
Hi:

Since Tornado 4.0 WebSocketHandler requires applications that wish to receive cross-origin websockets to opt in by overriding the check_origin method.

so, you can change your handler and overwrite "check_origin" like this:

class MainHandler(tornado.websocket.WebSocketHandler):

    def check_origin(*args, **kwargs):
        return True

Then, it will work.



在 2016年12月28日星期三 UTC+8上午12:59:58,Roman写道:

Roman Dvořák

unread,
Dec 28, 2016, 7:11:36 AM12/28/16
to python-...@googlegroups.com
Thank you so mutch, 

It works!

--
You received this message because you are subscribed to a topic in the Google Groups "Tornado Web Server" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-tornado/wyUFFCGThGQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-tornado+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages