问题

部署一个实时查看服务器日志的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;
}



如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!

阿里云ACK的CSI组件挂载NAS

CSI插件的安装与检测参照:https://help.aliyun.com/document_detail/204011.html?spm=a2c4g.11186623.6.579.15eb5dd20oLQ6z 确认是否已安装CSI插件 > kubect...

阅读全文

打包Java应用到镜像

目录结构 Shell . ├── Dockerfile # Dockerfile ├── pom.xml …… └── supports └── startup...

阅读全文

K8S Flannel网络 实现办公网与容器网络拉平互通

环境 办公网: 192.168.110.0/24 192.168.112.0/20 VPN网络: 192.168.202.0/24 服务器网络: 192.168.111.0/24 Service网络: ...

阅读全文

欢迎留言