Efficient rewrite

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.

Thanks,
-Jake

My guess is that method 1 would be more efficient because rewrite
processing would only happen if the location matched.

?? Just setup a small fixed page and then use “ab” from apache to
retrieve it a few thousand times… If it’s not measurable then it’s
not relevant? You would have to be doing quite a few per second for a
regexp to be a significant part of the page processing…

Just a thought?

Ed W

Thank you both for the insight.

-Jake

On Wed, Apr 09, 2008 at 03:26:57PM -0400, J Davis wrote:

}

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.