Skip to content

Commit 09d5e2c

Browse files
authored
Merge pull request #3360 from DarioViva42/hsts-only-with-https
only add hsts header with https.
2 parents 459b7a2 + 289e438 commit 09d5e2c

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

backend/templates/_hsts.conf

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)