Tags
configure nginx to redirect specific urls to https and back to http, HTTP Secure, Nginx, Nginx ssl configuration, ssl ciphers, ssl protocols, SSL-TLS
In our application there was a need to redirect few url’s to https and others back to http. So for e.g. i had to redirect sign-in, sign-up, etc to https and other url’s back to http.
Following are the things that i configured in nginx.conf to get it working.
#Section for http
server {
listen 80;
server_name http://www.example.com;
root /path-to-public-folder-of-project;
passenger_enabled on;
location ~ ^/(sign-up|sign-in) {
return 301 https://$host$request_uri;
}
}
#Section for https
server {
listen 443;
server_name http://www.example.com;
root /path-to-public-folder-of-project;
passenger_enabled on;
ssl on;
ssl_certificate /usr/local/nginx/ssl/example.com.crt;
ssl_certificate_key /usr/local/nginx/ssl/example.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Redirect all other requests to HTTP.
location ~ ^(?!/(sign-up|sign-in)) {
return 301 http://$host$request_uri;
}
}
The above configuration worked perfectly for me. Only specific url’s were being served through https and remaining through http.