Map v/s rewrite performance

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

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

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

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 S.
http://nginx.com

Igor S. Wrote:

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

Bingo! Never thought of this. :slight_smile:

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

Thanks a lot. :slight_smile:

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

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

Exact locations are faster.

Thanks again. We will go with exact locations. :slight_smile:

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

@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_module.html#fastcgi_cache_valid
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

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