2015-12-09 23:29:33 +02:00
|
|
|
{# helper variables and per-site defaults that we can't set in role defaults #}
|
2015-12-10 00:25:44 +02:00
|
|
|
{% set domain_name = item.domain_name %}
|
2016-08-17 12:55:14 +03:00
|
|
|
{# assume HSTS is off unless a vhost explicitly sets it to True #}
|
|
|
|
{% set enable_hsts = item.enable_hsts | default(False) %}
|
2016-06-27 19:07:48 +03:00
|
|
|
|
2016-06-27 23:52:39 +03:00
|
|
|
{# first, check if the current vhost has a custom cert (perhaps self-signed) #}
|
2016-07-05 19:42:26 +03:00
|
|
|
{% if item.tls_certificate_path is defined and item.tls_key_path is defined %}
|
2014-09-06 21:32:37 +03:00
|
|
|
|
2014-09-13 23:16:54 +03:00
|
|
|
# concatenated key + cert
|
|
|
|
# See: http://nginx.org/en/docs/http/configuring_https_servers.html
|
2016-06-27 19:07:48 +03:00
|
|
|
ssl_certificate {{ item.tls_certificate_path }};
|
|
|
|
ssl_certificate_key {{ item.tls_key_path }};
|
|
|
|
|
2016-06-27 23:52:39 +03:00
|
|
|
{# otherwise, assume host is using letsencrypt #}
|
2015-12-08 17:18:21 +02:00
|
|
|
{% else %}
|
2016-06-27 19:07:48 +03:00
|
|
|
|
2016-06-27 23:52:39 +03:00
|
|
|
# concatenated key + cert
|
|
|
|
# See: http://nginx.org/en/docs/http/configuring_https_servers.html
|
2021-03-19 23:39:30 +02:00
|
|
|
ssl_certificate {{ letsencrypt_root }}/certs/{{ domain_name }}.fullchain.pem;
|
|
|
|
ssl_certificate_key {{ letsencrypt_root }}/private/{{ domain_name }}.key.pem;
|
2016-06-27 19:07:48 +03:00
|
|
|
|
2015-12-08 17:18:21 +02:00
|
|
|
{% endif %}
|
2014-09-06 21:32:37 +03:00
|
|
|
|
2015-06-04 23:28:31 +03: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 22:17:52 +03:00
|
|
|
|
2015-06-04 23:28:31 +03:00
|
|
|
ssl_dhparam {{ nginx_ssl_dhparam }};
|
|
|
|
ssl_protocols {{ nginx_ssl_protocols }};
|
2014-09-06 21:32:37 +03:00
|
|
|
ssl_ciphers "{{ tls_cipher_suite }}";
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
|
2015-12-08 17:18:21 +02:00
|
|
|
{# OSCP stapling only works with real certs #}
|
2016-08-17 12:42:48 +03:00
|
|
|
{% if use_letsencrypt == True or item.tls_certificate_path %}
|
2014-12-06 23:21:46 +03:00
|
|
|
# OCSP stapling...
|
|
|
|
ssl_stapling on;
|
|
|
|
ssl_stapling_verify on;
|
2018-04-30 18:04:17 +03:00
|
|
|
resolver {{ nginx_ssl_stapling_resolver }};
|
2016-06-27 19:07:48 +03:00
|
|
|
{% endif %} {# end: use_letsencrypt #}
|
2014-12-06 23:21:46 +03:00
|
|
|
|
2014-12-06 22:37:00 +03: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;
|
|
|
|
|
2016-08-17 12:55:14 +03:00
|
|
|
{% if enable_hsts == True %}
|
2014-09-06 21:32:37 +03:00
|
|
|
# Enable this if you want HSTS (recommended, but be careful)
|
2015-05-20 15:56:19 +03:00
|
|
|
# Include all subdomains and indicate to Google that we want this pre-loaded in Chrome's HSTS store
|
|
|
|
# See: https://hstspreload.appspot.com/
|
2021-03-23 15:36:28 +02:00
|
|
|
add_header Strict-Transport-Security "max-age={{ nginx_hsts_max_age }}; includeSubDomains; preload" always;
|
2015-06-04 23:28:31 +03:00
|
|
|
{% endif %}
|