Last active
August 29, 2015 13:57
-
-
Save jeffbr13/9354450 to your computer and use it in GitHub Desktop.
Nginx virtual host configuration with HTTPS and redirection for common variants.
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
## /etc/nginx/sites_enabled/website.tld | |
# | |
# Nginx virtual host configuration for <https://website.tld>, | |
# redirecting all traffic from <http[s]://[www.]website.tld>. | |
server { | |
server_name website.tld; | |
root /var/www/website.tld; | |
# HTTPS (IPv4) | |
listen 443 ssl; | |
ssl_certificate /etc/nginx/ssl/website.tld.crt; | |
ssl_certificate_key /etc/nginx/ssl/website.tld.key; | |
location / { | |
index index.html index.htm index; | |
try_files $uri $uri/ $uri.html =404; | |
} | |
} | |
# Redirect <https://www.website.tld> to <https://website.tld> | |
server { | |
server_name www.website.tld; | |
listen 443 ssl; | |
return 301 https://website.tld$request_uri; | |
} | |
# Redirect HTTP traffic to HTTPS | |
server { | |
server_name website.tld; | |
# HTTP (IPv4) | |
listen 80; | |
return 301 https://website.tld$request_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment