Forum: NGINX map v/s rewrite performance

2974d09ac2541e892966b762aad84943?d=identicon&s=25 rahul286 (Guest)
on 2014-03-25 09:13
(Received via mailing list)
Hi All,

I am just wondering, say for 1000 url redirects, what will be more
efficient.

Rewrite Style:
============
server {
       rewrite          old-url-1         new-url-1 permanent;
       rewrite          old-url-2         new-url-2 permanent;
       rewrite          old-url-3         new-url-3 permanent;
       #....
       rewrite $old-url-1000    $new-url-1000 permanent;
}


Map Style:
============

map $request_uri $new_uri {
         default             $request_uri;
         old-url-1          new-url-1;
         old-url-2          new-url-2;
         old-url-3          new-url-3;
         #....
         old-url-1000    new-url-1000;
}

#and something like
server {
         try_files $new_uri =404;
}

Since nginx is very fast, I am not able to notice any delay for around
20
rewrites. :|

Is one of above 2 method is recommended for large number of rewrites?

I am inclined towards map, as rewrite adds plenty of notices logs. It's
like
every rewrite is checked for incoming requests unless it is surrounded
by
location.

Please let me know if more details are needed.

Thanks.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,248659,248659#msg-248659
0f7a1240e82f744c6c607fa7081b99f7?d=identicon&s=25 Igor Sysoev (Guest)
on 2014-03-25 09:16
(Received via mailing list)
On Mar 25, 2014, at 12:12 , rahul286 wrote:

>       rewrite          old-url-3         new-url-3 permanent;
>         old-url-1          new-url-1;
>
> Since nginx is very fast, I am not able to notice any delay for around 20
> rewrites. :|
>
> Is one of above 2 method is recommended for large number of rewrites?
>
> I am inclined towards map, as rewrite adds plenty of notices logs. It's like
> every rewrite is checked for incoming requests unless it is surrounded by
> location.
>
> Please let me know if more details are needed.

location = old-url-1 { return 301 new-url-1; }
...


--
Igor Sysoev
http://nginx.com
2974d09ac2541e892966b762aad84943?d=identicon&s=25 rahul286 (Guest)
on 2014-03-25 09:43
(Received via mailing list)
Igor Sysoev Wrote:
-------------------------------------------------------
> location = old-url-1 { return 301 new-url-1; }

Bingo! Never thought of this. :-)

We will use this for https://github.com/rtCamp/easyengine/issues/162

Thanks a lot. :-)

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,248659,248663#msg-248663
2974d09ac2541e892966b762aad84943?d=identicon&s=25 rahul286 (Guest)
on 2014-04-04 14:05
(Received via mailing list)
@Igor

Few Updates:

> location = old-url-1 { return 301 new-url-1; }

is really nice. We can specify 301/302 using it.

But I am reading -
http://nginx.org/en/docs/http/ngx_http_fastcgi_mod...
and now I am thining weather to populate config file with 1000's of
lines
like below (using automated script, no human efforts involved)

> location = old-url-1 { return 301 new-url-1; }

OR simply declare

> fastcgi_cache_valid 301 302      max;

That is: Putting load in config file v/s fastcgi-cache?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,248659,248994#msg-248994
0f7a1240e82f744c6c607fa7081b99f7?d=identicon&s=25 Igor Sysoev (Guest)
on 2014-04-06 10:02
(Received via mailing list)
On Apr 4, 2014, at 16:05 , rahul286 wrote:

> and now I am thining weather to populate config file with 1000's of lines
> like below (using automated script, no human efforts involved)
>
>> location = old-url-1 { return 301 new-url-1; }
>
> OR simply declare
>
>> fastcgi_cache_valid 301 302      max;
>
> That is: Putting load in config file v/s fastcgi-cache?

Exact locations are faster.


--
Igor Sysoev
2974d09ac2541e892966b762aad84943?d=identicon&s=25 rahul286 (Guest)
on 2014-04-06 15:49
(Received via mailing list)
> Exact locations are faster.

Thanks again. We will go with exact locations. :-)

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,248659,249046#msg-249046
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.