Skip to content

Instantly share code, notes, and snippets.

@aandrewww
Last active April 24, 2018 06:54
Show Gist options
  • Save aandrewww/33c6af82395725b2e21eb025b029832c to your computer and use it in GitHub Desktop.
Save aandrewww/33c6af82395725b2e21eb025b029832c to your computer and use it in GitHub Desktop.
Nginx example config with IPv6,HTTP/2 and A+ SLL rating
## http://example.com redirects to https://example.com
server {
listen 80;
listen [::]:80;
server_name example.com;
include /etc/nginx/snippets/letsencrypt.conf;
location / {
return 301 https://example.com$request_uri;
}
}
## http://www.example.com redirects to https://www.example.com
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name www.example.com;
include /etc/nginx/snippets/letsencrypt.conf;
location / {
return 301 https://www.example.com$request_uri;
}
}
## https://www.example.com redirects to https://example.com
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include /etc/nginx/snippets/ssl.conf;
return 301 https://example.com$request_uri;
}
## Serves https://example.com
server {
server_name example.com;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server ipv6only=on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include /etc/nginx/snippets/ssl.conf;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment