Performance penalty when using regular expressions in server_name?

Igor Sverkos igor.sverkos at googlemail.com
Wed Jan 29 19:52:21 UTC 2014


Hi,

let assume that we run the following domains:

 - agoodexample.org
 - agoodexmaple.com
 - agoodexample.net
 - a-good-example.org
 - a-good-example.com
 - a-good-example.net

Our main site should be www.a-good-example.com -- people coming from any
other mentioned domain/combination should be redirected to the main site.

I could now write a single server block like

 server {
     // ...
     server_name ~^(?:www\.)?a[-]?good-example\.(?:org|net)$
             ~^ a[-]?good-example\.com $;

     rewrite ^ $scheme://www.a-good-example.com $request_uri permanent;
 }

I am using regular expressions as server_name values, I think you get the
point.

I could also avoid regular expressions:

 server {
     // ...
     server_name agoodexample.org
             a-good-example.org
             www.agoodexample.org
             www.a-good-example.org
             agoodexample.net
             a-good-example.net
             www.agoodexample.net
             www.a-good-example.net
             agoodexample.com
             www.agoodexample.com
             a-good-example.com;

     rewrite ^ $scheme://www.a-good-example.com $request_uri permanent;
 }


Q1: Are both configurations equal or is there any performance difference?
    E.g. would you recommend one configuration more than the other?


Q2: When using regular expressions in server_name, the regular expression
    will also appear in the error_log. Is it possible to see the actual
    name instead the expression in the log?


I am using nginx-1.4.x with pcre-jit enabled.

Thanks.


-- 
Regards,
Igor



More information about the nginx mailing list