2015-12-09 22:29:33 +01:00
|
|
|
{# helper variables and per-site defaults that we can't set in role defaults #}
|
2015-12-08 16:19:46 +01:00
|
|
|
{% set domain_name = item.nginx_domain_name %}
|
2015-09-26 23:24:58 +02:00
|
|
|
{# assume HSTS is off unless a vhost explicitly sets it to "yes" #}
|
2015-12-08 16:19:46 +01:00
|
|
|
{% set enable_hsts = item.nginx_enable_hsts | default("no") %}
|
2015-12-08 16:18:21 +01:00
|
|
|
{# use self-signed certs? yes on development, no on production #}
|
|
|
|
{% set use_snakeoil_cert = item.use_snakeoil_cert | default("no") %}
|
2014-09-06 20:32:37 +02:00
|
|
|
|
2015-12-08 16:18:21 +01:00
|
|
|
{# better to check for "not yes" then "no" #}
|
|
|
|
{% if use_snakeoil_cert != "yes" %}
|
2014-09-13 22:16:54 +02:00
|
|
|
# concatenated key + cert
|
|
|
|
# See: http://nginx.org/en/docs/http/configuring_https_servers.html
|
2015-11-07 18:52:48 +01:00
|
|
|
ssl_certificate {{ tls_key_dir }}/{{ domain_name }}/fullchain.pem;
|
|
|
|
ssl_certificate_key {{ tls_key_dir }}/{{ domain_name }}/privkey.pem;
|
2015-12-08 16:18:21 +01:00
|
|
|
{% else %}
|
|
|
|
# "snakeoil" certificate (self signed!)
|
|
|
|
ssl_certificate /etc/ssl/certs/nginx-snakeoil.crt;
|
|
|
|
ssl_certificate_key /etc/ssl/private/nginx-snakeoil.key;
|
|
|
|
{% endif %}
|
2014-09-06 20:32:37 +02:00
|
|
|
|
2015-06-04 22:28:31 +02:00
|
|
|
ssl_session_timeout {{ nginx_ssl_session_timeout }};
|
|
|
|
ssl_session_cache {{ nginx_ssl_session_cache }};
|
|
|
|
ssl_buffer_size {{ nginx_ssl_buffer_size }};
|
2014-12-06 20:17:52 +01:00
|
|
|
|
2015-06-04 22:28:31 +02:00
|
|
|
ssl_dhparam {{ nginx_ssl_dhparam }};
|
|
|
|
ssl_protocols {{ nginx_ssl_protocols }};
|
2014-09-06 20:32:37 +02:00
|
|
|
ssl_ciphers "{{ tls_cipher_suite }}";
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
|
2015-12-08 16:18:21 +01:00
|
|
|
{# OSCP stapling only works with real certs #}
|
|
|
|
{% if use_snakeoil_cert != "yes" %}
|
2014-12-06 21:21:46 +01:00
|
|
|
# OCSP stapling...
|
|
|
|
ssl_stapling on;
|
|
|
|
ssl_stapling_verify on;
|
2015-11-30 16:40:32 +01:00
|
|
|
{% if linode_id is defined %}
|
|
|
|
# use Linode internal DNS
|
2015-03-22 17:06:33 +01:00
|
|
|
resolver 109.74.192.20 109.74.193.20;
|
2015-11-30 16:40:32 +01:00
|
|
|
{% else %}
|
|
|
|
resolver 8.8.8.8 8.8.4.4;
|
2015-12-08 16:18:21 +01:00
|
|
|
{% endif %} {# end: linode_id #}
|
|
|
|
{% endif %} {# end: use_snakeoil_cert #}
|
2014-12-06 21:21:46 +01:00
|
|
|
|
2014-12-06 20:37:00 +01:00
|
|
|
# nginx does not auto-rotate session ticket keys: only a HUP / restart will do so and
|
|
|
|
# when a restart is performed the previous key is lost, which resets all previous
|
|
|
|
# sessions. The fix for this is to setup a manual rotation mechanism:
|
|
|
|
# http://trac.nginx.org/nginx/changeset/1356a3b9692441e163b4e78be4e9f5a46c7479e9/nginx
|
|
|
|
#
|
|
|
|
# Note that you'll have to define and rotate the keys securely by yourself. In absence
|
|
|
|
# of such infrastructure, consider turning off session tickets:
|
|
|
|
ssl_session_tickets off;
|
|
|
|
|
2015-09-26 23:24:58 +02:00
|
|
|
{% if enable_hsts == "yes" %}
|
2014-09-06 20:32:37 +02:00
|
|
|
# Enable this if you want HSTS (recommended, but be careful)
|
2015-05-20 14:56:19 +02:00
|
|
|
# Include all subdomains and indicate to Google that we want this pre-loaded in Chrome's HSTS store
|
|
|
|
# See: https://hstspreload.appspot.com/
|
|
|
|
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
|
2015-06-04 22:28:31 +02:00
|
|
|
{% endif %}
|