Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created July 12, 2019 20:22
Show Gist options
  • Save rpayanm/648a9526cd4e12915cc20e1678ab656f to your computer and use it in GitHub Desktop.
Save rpayanm/648a9526cd4e12915cc20e1678ab656f to your computer and use it in GitHub Desktop.

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04

Redirect everything to SSL (personal config on UNIX with IPv4, IPv6, SPDY, ...): http://stackoverflow.com/a/11733363/2172151

#
# Redirect all www to non-www
#
server {
  server_name www.example.com;
  ssl_certificate ssl/example.com/crt;
  ssl_certificate_key ssl/example.com/key;
  listen *:80;
  listen *:443 ssl spdy;
  listen [::]:80 ipv6only=on;
  listen [::]:443 ssl spdy ipv6only=on;
  
  return 301 https://example.com$request_uri;
}

#
# Redirect all non-encrypted to encrypted
#
server {
  server_name example.com;
  listen *:80;
  listen [::]:80;
  
  return 301 https://example.com$request_uri;
}

#
# There we go!
#
server {
  server_name example.com;
  ssl_certificate ssl/example.com/crt;
  ssl_certificate_key ssl/example.com/key;
  listen *:443 ssl spdy;
  listen [::]:443 ssl spdy;
  
  # rest goes here...
}

Comprobar

curl -I http://www.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment