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 have a Web site where I want all requests to be done with HTTPS except for requests to urls with paths that start with /foo/. How do I configure this in Nginx?

Right now I run all requests with SSL:

server {
    listen 443;

    ssl on;
    ssl_certificate /home/admin/ssl/ssl.crt;
    ssl_certificate_key /home/admin/ssl/ssl.key;

    server_name www.mydomain.com;

    location / {
        proxy_pass http://localhost:8000;
        ...
    }
}
share|improve this question
    
Do you want to force requests to that path to not use SSL, or allow requests to not use SSL? –  Shane Madden May 24 '12 at 0:11
    
I want to allow requests to that path to use HTTP and HTTPS. –  hekevintran May 24 '12 at 0:17

1 Answer 1

up vote 8 down vote accepted

Add a second server entry for non-ssl, port 80, serving /foo/* and redirecting everything else to HTTPS URL.

Maybe something like this?:

server {
    listen      80;
    server_name www.example.com;

    location ~ ^/(foo|foo/.*)$ {
        proxy_pass http://localhost:8000;
        ... 
    }

    location / {
        rewrite  ^ https://$server_name$request_uri? permanent;
    }
}
share|improve this answer
    
Perfect answer. –  hekevintran May 24 '12 at 2:16

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.