Forum: NGINX Performance penalty when using regular expressions in server_name?

Bb9c2912739ece4181267a3866c0ce76?d=identicon&s=25 Igor Sverkos (Guest)
on 2014-01-29 20:52
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 itpp2012 (Guest)
on 2014-01-29 21:16
(Received via mailing list)
A different way would to use Lua and an alias table, for a dynamic site
I
use this to allow a site multiple aliases all directing to the same
root,
its a simple array with 2 lines for each main site, 1 as server_name and
line 2 endless aliases. Its fast and no need to edit nginx.conf just
edit a
plain ascii file.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246970,246973#msg-246973
0f7a1240e82f744c6c607fa7081b99f7?d=identicon&s=25 Igor Sysoev (Guest)
on 2014-01-30 07:53
(Received via mailing list)
On Jan 29, 2014, at 23:52 , Igor Sverkos wrote:

>
>     rewrite ^ $scheme://www.a-good-example.com $request_uri permanent;
>             a-good-example.org
>     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?

The second is faster but I believe performance is negligible.
And it's better to use

return 301 $scheme://www.a-good-example.com/$request_uri;

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

$host.


--
Igor Sysoev
http://nginx.com
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.