简体   繁体   English

NGINX proxy_pass 基于自定义标头

[英]NGINX proxy_pass based on custom header

I am setting up a reverse proxy on Nginx, and the client request has a header X-OUTBOUND-URI , which will then hit my reverse proxy on a particular port.我正在 Nginx 上设置反向代理,并且客户端请求具有标头X-OUTBOUND-URI ,然后它将在特定端口上访问我的反向代理。

I am trying to do a proxy_pass on the variable $http_x_outbound_uri , but there is a resolver error.我正在尝试对变量$http_x_outbound_uri执行 proxy_pass ,但存在解析器错误。

server {
        listen  8082;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
                proxy_pass $http_x_outbound_uri;
        }
}

This is the curl command that is used: curl localhost:8082 -H "X-OUTBOUND-URI: http://localhost:9001" , and I have a webserver running on port 9001.这是使用的 curl 命令: curl localhost:8082 -H "X-OUTBOUND-URI: http://localhost:9001" ,我有一个在端口 9001 上运行的网络服务器。

Am I doing this wrongly?我做错了吗? Also, for this use case, is it more suitable to do a redirect instead.此外,对于这个用例,是否更适合进行重定向。 Thanks.谢谢。

For those who have encountered the same issue, I managed to resolve this issue by changing localhost to 127.0.0.1, otherwise, we have to set a resolver.对于那些遇到同样问题的人,我设法通过将 localhost 更改为 127.0.0.1 来解决此问题,否则,我们必须设置解析器。 I found the explanation in another post .我在另一篇文章中找到了解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM