Rewriting https to http

Igor Sysoev is at rambler-co.ru
Fri Jan 12 00:41:10 MSK 2007


On Thu, 11 Jan 2007 ianevans at digitalhit.com wrote:

> How would I get nginx to rewrite from https to http unless the directory
> was one I specified? Here's how it's done in Apache:
>
> RewriteCond %{SERVER_PORT} ^443$
> RewriteCond $1 !^(securedir|2ndsecuredir|3rdsecuredir)/ [NC,OR]
> RewriteCond $1 !\.(css|gif|jpe?g|bmp|js|inc)$ [NC]
> RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]

Something like this:

     server {
         listen   443;

         location  /securedir/ {
             ...
         }

         location  /2ndsecuredir/ {
             ...
         }

         location  /3rdsecuredir/ {
             ...
         }

         location  ~* "\.(css|gif|jpe?g|bmp|js|inc)$" {
             ...
         }

         location  / {
             rewrite  ^(.+)   http://www.example.com$1  permanent;
         }
     }

The order of locaiton processing is described here:
http://wiki.codemongers.com/NginxHttpCoreModule#location


Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list