variable map for fastcgi_pass
Sergey Kandaurov
pluknet at nginx.com
Mon Sep 25 21:13:18 UTC 2017
> On 25 Sep 2017, at 22:12, Kyle Sloan <kyle at ifsight.com> wrote:
>
> Hello,
>
> I am trying to use a MAP function based on HOSTNAMES to determine if this domain should fastcgi_pass to a php5 or php7 container, but am having problems.
>
> My map looks like
>
> map $host $php_proxy_container {
> hostnames;
>
> default "php5fpm:9000";
>
> www.example.com "php7fpm:9000";
> }
>
>
> My fastcgi file looks like
>
> fastcgi_pass $php_proxy_container;
>
>
> [..]
>
> I get a generic 502 bad gateway, and nothing more in the http log. Changing the fastcgi_pass line to the exact value in the map and restarting does work.
>
If variable used within fastcgi_pass evaluates to something like
hostname:port, you need to define resolver to resolve that name.
http://nginx.org/r/resolver
OTOH, if that name is used within fastcgi_pass literally,
it would be resolved at startup by system resolver instead.
--
Sergey Kandaurov
More information about the nginx
mailing list