问题

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

CI/CD(五)Flink 应用部署

环境 代码托管:gitlab CI:tekton CD: tekton pipline/task: 阿里云 serverless容器(spot实例且按秒计费) 应用:K8S Flink 应用需要解决的是任务的灵活增...

阅读全文

阿里云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...

阅读全文

欢迎留言