From cd3cb06c6aa441a60a067627dd1eedb83fe12563 Mon Sep 17 00:00:00 2001 From: Oliver Cervera Date: Thu, 25 Feb 2021 12:18:02 +0100 Subject: [PATCH] Redirect HTTP to HTTPS on the same port This configuration allows to redirect any HTTP connection to HTTPS, on the same port. This is useful when using a custom port. I'm adding this config here because it needs to be included in every server configuration, not just the main one, and this file is included in each website configuration. --- root/defaults/ssl.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/root/defaults/ssl.conf b/root/defaults/ssl.conf index 654c512..a6ea979 100644 --- a/root/defaults/ssl.conf +++ b/root/defaults/ssl.conf @@ -38,6 +38,9 @@ ssl_early_data on; # HSTS, remove # from the line below to enable HSTS #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; +# Redirect http traffict to https on same port +error_page 497 301 =307 https://$host:$server_port$request_uri; + # Optional additional headers #add_header Cache-Control "no-transform" always; #add_header Content-Security-Policy "upgrade-insecure-requests; frame-ancestors 'self'";