Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to ensure that no one can go through the checkout process without https. How can I redirect anything that starts with /checktout (i.e. example.com/checkout & example.com/checkout/process) to https if it's not.

Vice versa, I don't want any page to be able to be accessed through https unless it has /checkout. So anything else should be redirected to http.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Use static location:

server {
        listen   80 default;
        server_name  example.com;

        access_log  /var/log/nginx/example.com.access.log;

        location / {
                root   /var/www/example.com;
        }

        location /checkout {
                rewrite         ^/(.*)$ https://example.com/$1 redirect;
        }
}

server {
    listen   443;
    server_name  example.com;

    location / {
            rewrite         ^/(.*)$ http://example.comt/$1 redirect;
    }

    location /checkout {
            root /var/www/example.com/checkout;
    }

    ssl  on;
    ssl_certificate  myssl.crt;
    ssl_certificate_key  myssl.key;

}
share|improve this answer
    
Correct approach, though you can use $request_uri or $uri to avoid the capture in your redirects. –  Martin Fjordvald Oct 15 '10 at 18:18
    
I like static location, because they are easy to add and edit –  bindbn Oct 15 '10 at 18:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.