10

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;
        ...
    }
}
  • 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
14

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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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