redirect - Nginx: dynamic proxy from url to subdomain -
i'm trying write nginx conf dynamically redirect url webapp, based on uri. use proxypass directive. example, want redirect http://www.example.com/clientname/ http://clientname.internaldomain.local/webapp
so far, succeded replacing new host, uri broken because can't split it. (now can't replace host, dunno why ...)
here actual non working conf:
server { resolver 192.168.137.71; listen 80; server_name tomservpa1; location ~ (^\/(.*)\/) { set $ccehost $2; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-forwarded-host $host; proxy_set_header x-forwarded-server $host; proxy_set_header x-real-ip $remote_addr; proxy_pass http://$ccehost.internaldomain.local:9780/webapp/$new_request_uri; proxy_redirect off; proxy_set_header host $host; } }
did ?
thanks.
you can use named captures in location
directive avoid scope , ambiguity issues. example:
location ~ ^/(?<ccehost>[^/]+)/(?<new_request_uri>.*)$ { rewrite ^ /webapp/$new_request_uri break; ... proxy_pass http://$ccehost.internaldomain.local:9780; ... }
Comments
Post a Comment