Home > database >  NGINX proxy_pass based on custom header
NGINX proxy_pass based on custom header

Time:05-27

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.

I am trying to do a proxy_pass on the variable $http_x_outbound_uri, but there is a resolver error.

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.

Am I doing this wrongly? Also, for this use case, is it more suitable to do a redirect instead. Thanks.

CodePudding user response:

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. I found the explanation in another post.

  • Related