0

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.

darkvalance
  • 390
  • 4
  • 14
  • 1
    What is stopping you from defining a resolver if you want to use `proxy_pass` in a way like that? Read [this](http://www.nginx-discovery.com/2011/05/day-51-proxypass-and-resolver.html) blog post. – Ivan Shatsky May 23 '22 at 09:59
  • I guess the right question is more on which is the more appropriate way to solve this problem for my use case? Because using a redirect works for me right now, but I'm not too sure if that's the right way to solve this problem. Thanks for the link, I'll read up on it! Much appreciated. – darkvalance May 23 '22 at 10:04
  • I don't know what is exactly your particular use case :) Probably you should read [this](https://stackoverflow.com/questions/42154249/difference-http-redirect-vs-reverse-proxy-in-nginx) thread first. – Ivan Shatsky May 23 '22 at 10:22
  • Thanks, I definitely need a reverse proxy then – darkvalance May 23 '22 at 15:53

1 Answers1

1

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.

darkvalance
  • 390
  • 4
  • 14