efficient rewrite

Igor Sysoev is at rambler-co.ru
Fri Apr 11 19:04:31 MSD 2008


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/





More information about the nginx mailing list