efficient rewrite

J Davis mrsalty0 at gmail.com
Mon Apr 14 17:01:34 MSD 2008


Thank you both for the insight.

-Jake


On Fri, Apr 11, 2008 at 11:04 AM, Igor Sysoev <is at rambler-co.ru> wrote:

> On Wed, Apr 09, 2008 at 03:26:57PM -0400, J Davis wrote:
>
> > Greetings.
> >
> > I want to redirect certain URL's to https. I've come up with a few ways
> that
> > I think will work but I'm wondering which method is more efficient in
> terms
> > of how much processing nginx would do.
> >
> > 1st method: multiple 'location' sections.
> >
> > location /sub1 {
> >     rewrite ^(.*) https://$host$1 redirect;
> > }
> > location /sub2 {
> >     rewrite ^(.*) https://$host/sub2 redirect;
> > }
> >
> > 2nd method: one location w/ multiple redirects.
> >
> > location / {
> >     rewrite ^(/sub1.*) https://$host$1 redirect;
> >     rewrite ^(/sub2.*) https://$host$1 redirect;
> > }
> >
> > 3rd method: match using $scheme.
> >
> > if ($scheme ~ http) {
> >     rewrite ^(/sub1.*) https://$host$1 redirect;
> >     rewrite ^(/sub2.*) https://$host$1 redirect;
> > }
> >
> > My guess is that method 1 would be more efficient because rewrite
> processing
> > would only happen if the location matched.
>
> 1st method is the faster.
> As to matching $scheme: you have to create two virtual servers - http and
> https,
> so http server will always have "http" scheme.
>
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080414/77e64c5f/attachment.html>


More information about the nginx mailing list