Last active
August 29, 2015 14:16
-
-
Save desaiuditd/ea99e6647879cae9441e to your computer and use it in GitHub Desktop.
Nginx Rules for Force HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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