@jeruthadam
Я крут

Как заменить часть урл переменной?

Можно ли как-то изменять урл proxy_pass в зависимости от хоста?

Вот это работает (хардкод)

proxy_pass http://media.static/mysite.com/static/robots.txt;


А вот это уже не работает

proxy_pass http://media.static/$host/static/robots.txt;


При этом $host это и есть mysite.com
  • Вопрос задан
  • 235 просмотров
Пригласить эксперта
Ответы на вопрос 1
ky0
@ky0 Куратор тега Nginx
Миллиардер, филантроп, патологический лгун
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 behaviour 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.

https://trac.nginx.org/nginx/ticket/1067
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы