这个我很难过。 我们在myserver.com/wsDemo?ID=12上的端口80上有一个websocket服务器。 我们需要通过代理连接到这个服务器来testing一个客户端程序。 我正在尝试nginx 1.2.7作为在代理服务器上运行的端口8080上的代理。 我们希望客户端使用http连接方法连接到代理,然后让代理创build到myserver.com/wsDemo?ID=12 websocket应用程序服务器的隧道。 这是我的nginxconfiguration:
http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server{ listen 8080; listen 80; location /wsDemo?ID=12 { proxy_pass http://myserver.com:80/wsDemo?ID=12; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include /etc/nginx/conf.d/*.conf; }
我会很乐意使用任何代理来完成这个,如果任何人有一个不同的工具,他们会build议(请添加一个configuration的例子是可能的)
nginx目前并不支持WebSocket协议。 支持它的第一个开发版本是2月20日的1.3.13 ( 来源:nginx.org )。
在达到生产就绪状态之前,您可能需要尝试使用nginx_tcp_proxy_module的nginx_tcp_proxy_module将WebSocket连接代理为普通TCP 。