Skip to content

Commit

Permalink
Merge pull request NginxProxyManager#3360 from DarioViva42/hsts-only-…
Browse files Browse the repository at this point in the history
…with-https

only add hsts header with https.
  • Loading branch information
jc21 authored Jan 8, 2024
2 parents 459b7a2 + 289e438 commit 09d5e2c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/templates/_hsts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% if ssl_forced == 1 or ssl_forced == true %}
{% if hsts_enabled == 1 or hsts_enabled == true %}
# HSTS (ngx_http_headers_module is required) (63072000 seconds = 2 years)
add_header Strict-Transport-Security "max-age=63072000;{% if hsts_subdomains == 1 or hsts_subdomains == true -%} includeSubDomains;{% endif %} preload" always;
add_header Strict-Transport-Security $hsts_header always;
{% endif %}
{% endif %}
{% endif %}
3 changes: 3 additions & 0 deletions backend/templates/_hsts_map.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
map $scheme $hsts_header {
https "max-age=63072000;{% if hsts_subdomains == 1 or hsts_subdomains == true -%} includeSubDomains;{% endif %} preload";
}
2 changes: 2 additions & 0 deletions backend/templates/_location.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% include "_hsts_map.conf" %}

location {{ path }} {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
Expand Down
3 changes: 3 additions & 0 deletions backend/templates/dead_host.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% include "_header_comment.conf" %}

{% if enabled %}

{% include "_hsts_map.conf" %}

server {
{% include "_listen.conf" %}
{% include "_certificates.conf" %}
Expand Down
3 changes: 3 additions & 0 deletions backend/templates/proxy_host.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% include "_header_comment.conf" %}

{% if enabled %}

{% include "_hsts_map.conf" %}

server {
set $forward_scheme {{ forward_scheme }};
set $server "{{ forward_host }}";
Expand Down
3 changes: 3 additions & 0 deletions backend/templates/redirection_host.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% include "_header_comment.conf" %}

{% if enabled %}

{% include "_hsts_map.conf" %}

server {
{% include "_listen.conf" %}
{% include "_certificates.conf" %}
Expand Down

0 comments on commit 09d5e2c

Please sign in to comment.