【发布时间】:2019-08-05 14:28:17
【问题描述】:
我们有一个网络服务器和一些与网络服务器并行运行的节点服务。这些服务都使用套接字,网络服务器也有一个套接字,然后浏览器使用 NGINX 的反向代理方面与所有这些进行通信。
现在,我们要设置 NGINX 以便它可以处理传入的 SSL(端口 443)请求,但网络服务器和套接字仍保留在端口 80 (http/ws) 上,基本上安全地包装了配置。
我们已经安装了证书(此时是自签名的),我可以让它的网络服务器方面工作,但是所有的套接字通信都会出错。
2019/03/14 10:27:31 [error] 14279#14279: *2 connect() failed (111: Connection refused) while connecting to upstream, client: ::1, server: _, request: "GET /web_app_socket/?EIO=3&transport=polling&t=Mbz1xMB HTTP/2.0", upstream: "http://127.0.0.1:3001/web/socket.io/?EIO=3&transport=polling&t=Mbz1xMB", host: "localhost", referrer: "https://localhost/"
在客户端,我得到了这个:
GET https://localhost/liveview/?EIO=3&transport=polling&t=Mbz1vtE 502
这是我在 default 配置文件中为网络服务器套接字的 NGINX 提供的内容:
location /web_app_socket/ { ### route the websockets of the web app
#Configure proxy to pass data to upstream service
proxy_pass http://web_app/web/socket.io/;
#HTTP version 1.1 is needed for sockets
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
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_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
}
我已经尝试了很多配置,以至于我迷失了应该是正确的方法来做到这一点(或者,NGINX 可以做到这一点吗?)。
【问题讨论】: