Welcome! Log In Create A New Profile

Advanced

Re: map module - mass hosting

Maxim Dounin
April 23, 2014 08:46AM
Hello!

On Wed, Apr 23, 2014 at 08:07:42AM -0400, beatnut wrote:

> I'd like to use map module for my vhost configuration to setup user name in
> root or fastcgi_pass parameter.
>
> At this point i've 300 domains configured and my config look like this:
>
> http
> {
> server {
> ..........
> root /home/someuser;

[...]

> I'd like to replace this model by using map module like this
>
>
> http
> {
>
> #map with about 300 domains
>
> map $http_host $username {
> example.com someuser;
> escample2.com someuser2;
> .......
> }
>
> server {
> ..........
> root /home/$username;

[...]

> My question is - Is this a good idea to use map like this ? Every request
> needs to find out username by $http_host searching through few hundreds of
> domains. Maybe i'm wrong but it can slow down request processing
> significantly.
> Any suggestions ?

Searching within a map is basically identical to searching for
appropriate server{} block, both use the same internal mechanism
(ngx_hash). As long as you don't use regular expressions,
lookup complexity is O(1).

Distinct server{} blocks might be more CPU-efficient due to no need to
evaluate variables and dynamically allocate memory for resulting
strings on each request.

On the other hand, multiple server{} blocks consume memory for
each server's configuration, and map{} approach may be more
effective if there are many mostly identical server{} blocks.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

map module - mass hosting

beatnut April 23, 2014 08:07AM

Re: map module - mass hosting

Maxim Dounin April 23, 2014 08:46AM

Re: map module - mass hosting

beatnut April 23, 2014 09:27AM

Re: map module - mass hosting

Maxim Dounin April 23, 2014 10:36AM

Re: map module - mass hosting

beatnut April 24, 2014 02:51AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 298
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready