Skip to content

Commit 289e438

Browse files
committed
only add hsts header with https.
fixes #1005 for more information look at: https://websistent.com/add-the-hsts-header-only-for-https-requests-nginx/
1 parent e08a4d4 commit 289e438

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

backend/templates/_hsts.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if ssl_forced == 1 or ssl_forced == true %}
33
{% if hsts_enabled == 1 or hsts_enabled == true %}
44
# HSTS (ngx_http_headers_module is required) (63072000 seconds = 2 years)
5-
add_header Strict-Transport-Security "max-age=63072000;{% if hsts_subdomains == 1 or hsts_subdomains == true -%} includeSubDomains;{% endif %} preload" always;
5+
add_header Strict-Transport-Security $hsts_header always;
66
{% endif %}
77
{% endif %}
88
{% endif %}

backend/templates/_hsts_map.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
map $scheme $hsts_header {
2+
https "max-age=63072000;{% if hsts_subdomains == 1 or hsts_subdomains == true -%} includeSubDomains;{% endif %} preload";
3+
}

backend/templates/_location.conf

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% include "_hsts_map.conf" %}
2+
13
location {{ path }} {
24
proxy_set_header Host $host;
35
proxy_set_header X-Forwarded-Scheme $scheme;

backend/templates/dead_host.conf

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% include "_header_comment.conf" %}
22

33
{% if enabled %}
4+
5+
{% include "_hsts_map.conf" %}
6+
47
server {
58
{% include "_listen.conf" %}
69
{% include "_certificates.conf" %}

backend/templates/proxy_host.conf

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% include "_header_comment.conf" %}
22

33
{% if enabled %}
4+
5+
{% include "_hsts_map.conf" %}
6+
47
server {
58
set $forward_scheme {{ forward_scheme }};
69
set $server "{{ forward_host }}";

backend/templates/redirection_host.conf

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% include "_header_comment.conf" %}
22

33
{% if enabled %}
4+
5+
{% include "_hsts_map.conf" %}
6+
47
server {
58
{% include "_listen.conf" %}
69
{% include "_certificates.conf" %}

0 commit comments

Comments
 (0)