这是我的 nginx 配置
server {
listen 80;
server_name _;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://flask:8001;
}
location /socket.io {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://flask:8001/socket.io;
}
}
基于此代码的应用程序
结果,我无法通过代码从客户端页面连接到 websocket
var socket = io.connect(location.protocol + '//' + document.domain + ':' + (location.port || 80) + namespace)
当我尝试include proxy_params;
在 nginx 配置中使用行时,我得到 2018/03/06 19:52:06 [emerg] 1#1: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:6
我错在哪里以及如何允许 nginx 检索 websocket 连接?