variable map for fastcgi_pass

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

variable map for fastcgi_pass

Kyle Sloan
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 have tried also moving the :9000 of the mapping to the the fastcgi_pass to look like  fastcgi_pass   $php_proxy_container:9000 but alas it did not work either.

I am using MAPs in other places in this same format and they work.

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.


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: variable map for fastcgi_pass

Sergey Kandaurov

> On 25 Sep 2017, at 22:12, Kyle Sloan <[hidden email]> 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

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: variable map for fastcgi_pass

Kyle Sloan
Thanks for the response.  Both the variables respond/work when they are not maps/variables and just set.  I will try out the resolver and see if I can make any progress with it.

Kyle Sloan
DevOps Engineer | Interpersonal Frequency
[hidden email]
https://ifsight.com

On Sep 25, 2017, at 4:13 PM, Sergey Kandaurov <[hidden email]> wrote:


On 25 Sep 2017, at 22:12, Kyle Sloan <[hidden email]> 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

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx