Skip to content

Instantly share code, notes, and snippets.

Last active Dec 7, 2020
What would you like to do?
My nginx include for TLS A+ rating at using nginx/1.14.* and openssl 1.1.1*
# version 2020 feb 24
ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;
ssl_trusted_certificate /etc/letsencrypt/live/;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
# generated using:# openssl dhparam -dsaparam -out /etc/ssl/dh4096.pem 4096
ssl_dhparam /etc/ssl/dh4096.pem;
ssl_ecdh_curve secp384r1;
ssl_stapling on;
ssl_stapling_verify on;
# I use local dnsmasq for faster lookups, highly recommend it!
resolver [::1] valid=4h;
resolver_timeout 9s;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:18m;
ssl_session_tickets off;
ssl_buffer_size 4k;
include /etc/nginx/headers;
Copy link

jult commented Nov 16, 2017

Regarding the resolver entry:
You can easily mitigate this (using dnsmasq, like I did, for example)..
Don't forget to add the ipv6 localhost, i.e. [::1]

Copy link

jult commented Nov 16, 2017

All this is with letsencrypt certs, generated using certbot..

Copy link

Sudrien commented Mar 21, 2018

Came across this looking for a good cipher list -

resolver valid=300s ipv6=off;

is also an option if you don't have ipv6 support.

Copy link

jult commented Feb 28, 2019

Copy link

jult commented Feb 24, 2020

my include /etc/nginx/headers file contents;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header Referrer-Policy no-referrer-when-downgrade always;
# add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:;" always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-Content-Type-Options nosniff always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Feature-Policy "accelerometer 'none';ambient-light-sensor 'none';autoplay 'none';camera 'none';encrypted-media 'none';fullscreen 'self';geolocation 'self';gyroscope 'none';magnetometer 'none';microphone 'none';midi 'none';payment 'self';picture-in-picture 'none';speaker 'self';sync-xhr 'none';usb 'none';vibrate 'none';vr 'none';";

See for the stuff relating to HSTS preload.

Note that as soon as some nginx config (could be any snippet you use for a server) has a 'new' add_header entry, all previously set ones are gone. So, here's my pro tip:
Put an
include /etc/nginx/headers;
after every new header you've set, or at the bottom of your server/vhost conf file.

Then test if the headers are still sent using ssllabs, and/or

Copy link

jult commented Dec 7, 2020

don't use
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:;" always;
it ruins all iframes and/or embedded remote media.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment