问题: django+gunicorn+nginx, WebSocket无法正常连接
关键词: nginx, WebSocket
时间: 2017/06/12
描述:
var socket = new WebSocket("ws://" + window.location.host + "/chatrooms/online_user/" + userid + "/");
server {
listen 80;
server_name 192.168.31.137;
access_log /var/log/nginx/bbank.log;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
server {
listen 80;
server_name 192.168.31.137;
access_log /var/log/nginx/bbank.log;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
至此, websocket正常连接.