gpt4 book ai didi

sockets - 配置 NGINX 以使用 SSL 包装非 SSL 服务

转载 作者:太空宇宙 更新时间:2023-11-03 14:28:02 28 4
gpt4 key购买 nike

我们有一个网络服务器和许多与网络服务器并排运行的节点服务。所有服务都使用套接字,网络服务器也有一个套接字,然后浏览器使用 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

这是我在网络服务器套接字的 NGINX 的 default 配置文件中的内容:

    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 可以做到这一点吗?)。

最佳答案

是的,解决了这个问题。我刚刚删除了 proxy_redirect off; 并且它起作用了。

现在,它看起来像这样:

    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_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;
}

关于sockets - 配置 NGINX 以使用 SSL 包装非 SSL 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55166841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com