Nginx运行在Docker中,无法代理请求到本地网络的HyperHDR服务器。

huangapple go评论64阅读模式
英文:

Nginx running in Docker unable to proxy requests to local network HyperHDR server

问题

我无法通过Nginx代理请求到运行在本地网络上的服务器。请求没有成功传递,最终由请求方超时。

我正尝试调用一个json-rpc API(HyperHDR),该API与请求方软件(运行在Node.js上的Homebridge)设置的Content-Length标头不兼容,因此我正在设置Nginx作为代理,删除不兼容的标头。

如果我从Docker容器内部和外部直接使用curl访问服务器,连接是有效的,但通过Nginx无法。我不确定我的nginx.conf文件是否有问题?接收端的日志中没有任何内容,这与其他请求的情况相同,因此似乎请求没有传递。我可以在Nginx日志中看到请求在被代理后(使用正确的代理URL)超时,所以请求确实传递到了Nginx,但由于某种原因未完全传递。

nginx.conf

events {}

http {
  server {
    listen 8080;
    listen [::]:8080;
    error_log /var/log/nginx/error.log debug;

    location /json-rpc {
      proxy_pass http://192.168.1.205:8090/json-rpc;
      proxy_set_header Host $http_host;
    }
  }
}

Dockerfile

FROM nginx:latest
COPY nginx.conf /etc/nginx/conf.d/default.conf

我已经三次检查了在proxy_pass中指定的IP、端口和端点是否正确 - 如上所述,使用Curl调用它是有效的。

英文:

I'm unable to proxy requests via Nginx to a server running on local network. The requests aren't going through and eventually are timed out by the requester.

I'm attempting to call a json-rpc API (HyperHDR), which is incompatible with the Content-Length header set by the requesting piece of software (Homebridge that runs on Node.js), so I'm setting up Nginx as a proxy that drops the incompatible header.

The connection works if I curl the server directly from within and outside the Docker container, but not via Nginx. Not sure if there's something wrong with my nginx.conf? There's nothing in the logs of the receiving end, which is the case with other requests, so it seems the requests are not going through. I can see the requests timing out in the Nginx logs after being proxied (with the correct proxy URL), so the requests do get through to Nginx but for some reason are not going through all the way.

nginx.conf

events {}

http {
  server {
    listen 8080;
    listen [::]:8080;
    error_log /var/log/nginx/error.log debug;

    location /json-rpc {
      proxy_pass http://192.168.1.205:8090/json-rpc;
      proxy_set_header Host $http_host;
    }
  }
}

Dockerfile

FROM nginx:latest
COPY nginx.conf /etc/nginx/conf.d/default.conf

I've triple checked that the IP, port and endpoint specified in the proxy_pass are correct - calling it works with Curl as mentioned.

答案1

得分: 1

问题与Connection头有关。按照这个解决方案中所示清除它可以解决这个问题。

英文:

The issue was related to something to do with the Connection header. Clearing it as shown in this solution fixed the issue.

huangapple
  • 本文由 发表于 2023年5月29日 22:43:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358262.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定