8-04 1 views
问题
部署一个实时查看服务器日志的Django项目,完成后 点击调用WebSocket时 报错 Error during WebSocket handshake: Unexpected response code: 500
原因
经排查nginx的location缺少参数导致无法建立长连接
解决
添加
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
完整配置如下
upstream cfweb {
server 127.0.0.1:8000 weight=5 fail_timeout=5s max_fails=10;
}
server {
listen 80;
server_name cf.com;
location /{
proxy_pass http://cfweb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffers 32 32k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
access_log /data/logs/nginx/cf.com.access.log;
error_log /data/logs/nginx/cf.error.log;
}