Map FastCGI Ports Dynamically

Volodymyr Kostyrko c.kworr at gmail.com
Thu Feb 23 08:02:30 UTC 2012



justin wrote:
> Valentin,
>
> Ok, well I am almost there. The problem is since we need to define the
> map block outside of server, the $user variable is not defined yet.
> I.E.

First. You are already in `http`, so adding another http block would not 
help you.

>
> http {
>    # $user is not defined yet, it comes from inside server {}
>    map $user $user_fastcgi_port {
>      default 9000;
>      justin 9001;
>      simon 9002;
>    }
> }

So why not map to $http_host?

map $http_host $user_fastcgi_port {
	default			9000;
	justin.my.domain.com	9001;
	simon.my.domain.com	9002;
}

You'll save yourself one regexp search.

>
> server {
>    # Set's $user
>    server_name ~^(?<user>.+)\.my\.domain\.com$;
> }


-- 
Sphinx of black quartz judge my vow.



More information about the nginx mailing list