我正在尝试使用nginx代理websocket到端口80。我们在端口8080上运行tomcat应用程序,在端口8888上运行节点应用程序。我一直在尝试使用nginx代理他们到端口80,但由于某种原因连接没有建立。我在控制台得到以下错误:
WebSocket连接到'ws://chat-local-dev.guestops.com/ws/chat?access_token=bfb83713f8abecb6c3d36d3dc74c31b9&sessionId=undefined'失败:WebSocket在连接建立之前被关闭。
下面是我的nginx配置: worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name chat-local-dev.guestops.com;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name api-local-dev.guestops.com;
location / {
proxy_pass http://localhost:8881;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name console-local-dev.guestops.com;
location / {
proxy_pass http://localhost:8888;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
}
我能够在端口80上运行站点,但是我无法在客户端和服务器之间运行聊天。
任何帮助将不胜感激,我可以提供的节点文件,以及,但他们是一大串文件,但我可以提供必要的文件,如果需要。
我希望我说得足够清楚。提前感谢!
nginx在1.3版本中增加了websocket支持。所以你必须升级到1.3版本。