Disable SSL for certain paths in Nginx
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;
...
}
}
Solution 1:
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;
}
}