Skip to content

Instantly share code, notes, and snippets.

@desaiuditd
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desaiuditd/ea99e6647879cae9441e to your computer and use it in GitHub Desktop.
Save desaiuditd/ea99e6647879cae9441e to your computer and use it in GitHub Desktop.
Nginx Rules for Force HTTPS
#WWW to HTTPS+non-WWW
server {
server_name www.example.com ;
return 301 https://example.com$request_uri ;
}
#WWW to HTTPS+non-WWW
server {
listen 443 ;
server_name www.example.com ;
ssl_certificate /var/www/example.com/cert/example.com.crt;
ssl_certificate_key /var/www/example.com/cert/example.com.key;
return 301 https://example.com$request_uri ;
}
#HTTP to HTTPS
server {
listen 80;
server_name example.com *.example.com;
return 301 https://example.com$request_uri ;
}
server {
listen 443;
server_name example.com www.example.com;
ssl on;
ssl_certificate /var/www/example.com/cert/example.com.crt;
ssl_certificate_key /var/www/example.com/cert/example.com.key;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
root /var/www/example.com/htdocs;
index index.php index.htm index.html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment