efficient rewrite

J Davis mrsalty0 at gmail.com
Wed Apr 9 23:26:57 MSD 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080409/ef683295/attachment.html>


More information about the nginx mailing list