Answer the question
In order to leave comments, you need to log in
How to replace part of the url with a variable?
Is it possible to somehow change the proxy_pass url depending on the host?
Here it works (hardcode)
proxy_pass http://media.static/mysite.com/static/robots.txt;
proxy_pass http://media.static/$host/static/robots.txt;
Answer the question
In order to leave comments, you need to log in
Using variables in proxy_pass implies that the URI specified is a full one. Quoting the documentation:
A server name, its port and the passed URI can also be specified using variables:
proxy_pass http://$host$uri;
This behavior is not very intuitive, though it's how it works. Variables in proxy_pass were introduced
If you want nginx to use URI of the original request instead of the one specified in the proxy_pass, avoid specifying URI at all (note no trailing slash):
proxy_pass http://$host;
If you want to pass some changed URI, you can do so by using rewrite ... break in the same location.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question