我正在尝试使用nginx代理WebSocket + HTTP流量。
我已经阅读了这个:http://nginx.org/en/docs/http/websocket.html
我的配置看起来像:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name ourapp.com;
location / {
proxy_pass http://127.0.0.1:100;
proxy_http_version 1.1;
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;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
我有2个问题:
1)连接每分钟关闭一次。
2)我想在同一个端口上运行HTTP和WS。 应用程序在本地工作正常,但是如果我尝试将HTTP和WS放在同一个端口上并设置此nginx代理,则会出现以下错误:
WebSocket 到 'ws://ourapp.com/ws' 的连接失败:意外的响应代码:200
加载应用程序(HTTP)似乎正常工作,但WebSocket连接失败。