Map module - mass hosting

Hello all,

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;

  location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/www/someuser/fpm.socket;

include fastcgi_params.conf;

}

 ............
  }

}

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;

  include fastcgi.conf;

 ............
  }

}

fastcgi.conf:

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/www/$username/fpm.socket;

include fastcgi.conf;

}

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 ?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249475,249475#msg-249475

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;

[…]

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 D.
http://nginx.org/

Thank You for answer.
I’ve additional questions.

Maxim D. Wrote:

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).

So using for example:

.example.com
or
example.*

have more complexity or it shoud have full list of subdomains for
better
performance:

www.example.com
example.com
example.somedomain.com

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.

My configuration include one file with server{} per domain.
exaple.com.conf
example2.conf
etc

The main improvement i’d like to implement is to have one file with php
config like fastcgi.conf above and then include it in every server{}
Map module gives me this opportunity.

[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249475,249481#msg-249481

Thank You for explanation and advise.

Maxim D. Wrote:

www.example.com

strings on each request.
Map module gives me this opportunity.

Maxim D.
http://nginx.org/


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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249475,249513#msg-249513

Hello!

On Wed, Apr 23, 2014 at 09:27:33AM -0400, beatnut wrote:

[…]

have more complexity or it shoud have full list of subdomains for better
performance:

www.example.com
example.com
example.somedomain.com

While wildcards require more work on each lookup, complexity is
still O(1). Note that regular expressions != wildcard names.

The main improvement i’d like to implement is to have one file with php
config like fastcgi.conf above and then include it in every server{}
Map module gives me this opportunity.

This is not something I would recommend to do. If you have
server{} block per domain, you should have enough data to write
configuration without introducing another map ($document_root,
$server_name, and so on).

Please also see this FAQ article:

http://nginx.org/en/docs/faq/variables_in_config.html


Maxim D.
http://nginx.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs