群晖nas容器中生成的项目,使用npm反向代理后,容器上打开终端机显示error socker已关闭如何解决

群晖相关2年前更新 billconan
297 0

群晖nas容器中生成的项目,使用npm反向代理后,容器上打开终端机显示error socker已关闭,但是在局域网用ip访问群晖后再dokcer容器打开就能使用,如何解决。答案就是在反向代理npm中的advanced设置如下配置:

前期代码如下:

location / {

proxy_pass http://群晖IP:输入的端口号5000;

# proxy_pass http://1.1.1.1:5000;(这一句是注释,粘贴时删除掉)

proxy_set_header Host $http_host;

proxy_redirect http:// https://;

proxy_set_header X-Forwarded-Host $http_host;

proxy_set_header X-Forwarded-Port $server_port;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Forwarded-Scheme $scheme;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection $http_connection;

proxy_http_version 1.1;

}

请注意,对于 X-Forwarded-For 头,我使用了 $proxy_add_x_forwarded_for 而不是 $remote_addr。这是因为 $proxy_add_x_forwarded_for 包含了客户端的原始 IP 地址以及任何中间代理的 IP 地址,这有助于跟踪请求的完整路径。而 $remote_addr 只包含直接连接到 Nginx 的客户端的 IP 地址。

此外,请确保 proxy_pass 指令中的地址 http://172.17.0.1:5000 是你想要代理到的后端服务的正确地址和端口。这个地址应该是你的群晖容器或其他你想要代理的服务的内部地址。

更改后的:

location / {
proxy_pass http://172.17.0.1:5000;
proxy_set_header Host $http_host;
proxy_redirect http:// https://;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
}

 

© 版权声明

相关文章