Change target host in proxy_pass

Lucas Rolff lucas at lucasrolff.com
Fri Mar 17 11:47:21 UTC 2017


You can proxy_set_header Host – that should override whatever is defined in proxy_pass

From: nginx <nginx-bounces at nginx.org<mailto:nginx-bounces at nginx.org>> on behalf of Tomasz Kapek <kapekto1 at gmail.com<mailto:kapekto1 at gmail.com>>
Reply-To: "nginx at nginx.org<mailto:nginx at nginx.org>" <nginx at nginx.org<mailto:nginx at nginx.org>>
Date: Friday, 17 March 2017 at 12.12
To: "nginx at nginx.org<mailto:nginx at nginx.org>" <nginx at nginx.org<mailto:nginx at nginx.org>>
Subject: Change target host in proxy_pass

Hello,
I have NGINX acting as reverse proxy and I would like to achieve something like this:

When I get a request like this GET http://app1.mydomain.aa.com/aaa/bbb it should be converted to:
GET http://app1.mydomain.bb.com/aaa/bbb so such directive will do the job:

proxy_pass http://app1.mydomain.bb.com;
problem is that I want to convert host part automatically (regex) basing on incoming requests to NGINX  - app1.mydomain are not fixed they are changing very often.
Is it possible? Can anyone get a clue how proxy_pass statement should look like?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20170317/9369e058/attachment.html>


More information about the nginx mailing list