所以我在2天的大部分时间里一直撞到墙上,请帮忙.
我正在尝试使用它建立Websocket连接
django-websocket-redis配置.
有两个uwsgi运行实例,一个用于网站,一个用于websocket通信.
我大量使用wireshark来找出究竟发生了什么,显然Nginx正在吃标题“Connection:Upgrade”和“Upgrade:websocket”.
这是关键的Nginx配置部分:
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;
}
正如您在2 screenshots上看到的那样,内部通信的tcpdump表明握手工作正常.但在我的浏览器(第二张图片)中,标题丢失了.
任何想法都非常感谢.我真的被困在这里:(
版本:
Nginx - 1.7.4
uwsgi - 2.0.7
pip冻结:
Django的== 1.7
在MysqL-python的== 1.2.5
Django的Redis的-会议== 0.4.0
Django的WebSocket的,Redis的== 0.4.2
GEVENT == 1.0.1
greenlet == 0.4.4
Redis的== 2.10.3
6 == 1.8.0
uWSGI == 2.0.7
==的wsgiref 0.1.2
我记得我在gunicorn文档上看到了这个:
If you want to be able to handle streaming request/responses or other
fancy features like Comet,Long polling,or Web sockets,you need to
turn off the proxy buffering. When you do this you must run with one
of the async worker classes.To turn off buffering,you only need to add proxy_buffering off; to
your location block:
在您的位置将是:
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;
}
链接到gunicorn指南,用于在Nginx中部署.
http://docs.gunicorn.org/en/latest/deploy.html?highlight=header
希望这可以帮助