Websocket支持是从1.3.13开始的,所以我应该拥有它。
有人可以请我提供一个最简单的configuration示例,该configuration允许我的nginx(在Centos 6上)代理接受来自我的客户端的HTTP Connect,然后代理将代表客户端在另一台服务器上build立到另一台服务器的后端的websocket连接和客户端和websocket服务器之间的代理通信?
我一直在努力,只有400错误。 我会很感激。
我努力了:
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; }
重点是,该location不匹配查询string (问号背后的东西)。
你将不得不使用如下的东西:
location /wsDemo { if($arg_ID = 12) { proxy_pass http://myserver.com:80/wsDemo?ID=12; break; } proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }