From edb3be64eabd22cb14fc4057a6835e38d717fe0d Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Sun, 25 Feb 2018 11:18:42 -0300 Subject: [PATCH] Only add HSTS headers in HTTPS (#2143) --- rootfs/etc/nginx/template/nginx.tmpl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 35aa0d148..df57c2d19 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -613,10 +613,6 @@ stream { {{ end }} {{ end }} - {{ if (and (not (empty $server.SSLCertificate)) $all.Cfg.HSTS) }} - more_set_headers "Strict-Transport-Security: max-age={{ $all.Cfg.HSTSMaxAge }}{{ if $all.Cfg.HSTSIncludeSubdomains }}; includeSubDomains{{ end }};{{ if $all.Cfg.HSTSPreload }} preload{{ end }}"; - {{ end }} - {{ if not (empty $server.CertificateAuth.CAFileName) }} # PEM sha: {{ $server.CertificateAuth.PemSHA }} ssl_client_certificate {{ $server.CertificateAuth.CAFileName }}; @@ -684,6 +680,12 @@ stream { {{ end }} location {{ $path }} { + {{ if (and (not (empty $server.SSLCertificate)) $all.Cfg.HSTS) }} + if ($scheme = https) { + more_set_headers "Strict-Transport-Security: max-age={{ $all.Cfg.HSTSMaxAge }}{{ if $all.Cfg.HSTSIncludeSubdomains }}; includeSubDomains{{ end }};{{ if $all.Cfg.HSTSPreload }} preload{{ end }}"; + } + {{ end }} + port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }}; {{ if $all.Cfg.EnableVtsStatus }}{{ if $location.VtsFilterKey }} vhost_traffic_status_filter_by_set_key {{ $location.VtsFilterKey }};{{ end }}{{ end }}