0

Nginx how to retain the hostname in the uri and perform rewrite

location /app1/ {
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    rewrite /app1/(.*) /$1 break;
    proxy_pass <**how to pass the incoming request hostname as it is without hardcoding it**>
 } 

proxy_pass

Sairam
  • 3
  • 1
  • The hostname from the original request can be passed using `proxy_set_header Host $host;` (see [example](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#example)). The rewrite can be achieved using the `rewrite ... break` or the built-in functionality of `proxy_pass` (see [documentation](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass)). – Richard Smith Jan 09 '23 at 08:21
  • @RichardSmith can u pls share the syntax for setting the hostname from the request in the proxy_pass ( without hardcoding ) ? – Sairam Jan 09 '23 at 09:39

0 Answers0