Nginx consumes Upgrade header after proxy_pass

So, I hit my head against the wall for most of 2 days, please help.

I am trying to establish a connection with Websocket using this django-websocket-redis . There are 2 instances of uwsgi startup, one for the website and one for sharing via web connection.

I used wirehark heavily to find out exactly what was going on, and apparently nginx eats the "Connection: Upgrade" and "Upgrade: websocket" headers.

here is the critical part of nginx configuration:

upstream websocket { server 127.0.0.1:9868; } location /ws/ { proxy_pass_request_headers on; access_log off; proxy_http_version 1.1; proxy_pass http://websocket; proxy_set_header Connection "Upgrade"; proxy_set_header Upgrade websocket; } 

As you can see in these 2 screenshots , tcpdump internal communication shows that a handshake works great. but in my browser (second image) headers are missing.

Any ideas are welcome. I'm really stuck here :(

Versions:

 nginx - 1.7.4 uwsgi - 2.0.7 

pipette freezing: Django == 1.7 MySQL-python == 1.2.5 Django-Redis-sessions == 0.4.0 Django-WebSocket-Redis == 0.4.2 GEvent == 1.0.1 greenlet == 0.4.4 Redis == 2.10.3 six == 1.8.0 uWSGI == 2.0.7 wsgiref == 0.1.2

+7
django nginx websocket uwsgi
source share
1 answer

I would use gunicorn to deploy the django application, but anyway.

I remembered that I saw this in the shooting documents:

If you want to be able to handle requests / responses by stream or others such as Comet, Long polling or Web sockets, you need to disable proxy buffering. When you do this, you must work with one of the working classes of asynchronous programming.

To disable buffering, you only need to add proxy_buffering; to your location block:

At your location will be:

 location /ws/ { proxy_pass_request_headers on; access_log off; proxy_http_version 1.1; proxy_redirect off; proxy_buffering off; proxy_pass http://websocket; proxy_set_header Connection "Upgrade"; proxy_set_header Upgrade websocket; } 

Link to the shooting guide for deployment in nginx. http://docs.gunicorn.org/en/latest/deploy.html?highlight=header

Hope this helps

+1
source share

All Articles