Nginx RP: a lot of rewrite rules

Francis Daly francis at daoine.org
Thu Apr 4 18:19:11 UTC 2013


On Thu, Apr 04, 2013 at 12:20:42PM +0200, Davide D'Amico wrote:
> Il 04/04/13 11:34, Francis Daly ha scritto:
> >On Thu, Apr 04, 2013 at 09:01:17AM +0200, Davide D'Amico wrote:

Hi there,

> >I suspect that the suggestions are increasingly more efficient -- but
> >you presumably have the interest to find out for sure, on your hardware
> >and with your expected loads.
> 
> Thank you Francis, but I cannot "group" all the rewrite I have so I am 
> starting using all these rewrites on backends (where I have rewritemaps, 
> too) and later I'll test them on nginx.

I may have been unclear. I'm not talking about grouping the rewrites;
I'm talking about a list of desired old -> new redirections, which
presumably you have somewhere.

Get the /oldN -> /newN local urls that you care about, and in nginx you
can try (and I have now tested this):

===
http {

  map $uri $new {
    default "";
    /old3 /new3;
    /old4 /new4;
  }  

  server {
    listen 8000;

    if ($new) {
      return 301 $new;
    }

    location = /old1 { return 301 /new1 ;}
    location = /old2 { return 301 /new2 ;}
  }

}
===

and look at the output of things like

  curl -I http://localhost:8000/old1

Test twice, once with many "location =" lines and no map/if; and the other
time with many lines inside the map and no special "location =" lines;
in order to know which is better on your system.

Anyway, if you have something working well enough for you now, then you
don't need to change anything. But when the time comes, this is a more
specific example of what I was suggesting.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list