apache:setting_up_hsts_in_apache
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
apache:setting_up_hsts_in_apache [2019/11/29 16:19] – removed peter | apache:setting_up_hsts_in_apache [2022/06/14 08:13] (current) – created peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Ubuntu - Apache - Setting up HSTS in Apache ===== | ||
+ | Edit your **apache** configuration file (/ | ||
+ | |||
+ | <file apache / | ||
+ | # Optionally load the headers module: | ||
+ | LoadModule headers_module modules/ | ||
+ | |||
+ | < | ||
+ | Header always set Strict-Transport-Security " | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Now your website will set the header every time someone visits, with an expiration date of two years (in seconds). | ||
+ | |||
+ | You do have to set it on the HTTPS vhost only. It cannot be in the HTTP vhost. | ||
+ | |||
+ | To redirect your visitors to the HTTPS version of your website, use the following configuration: | ||
+ | |||
+ | <file apache> | ||
+ | < | ||
+ | [...] | ||
+ | ServerName example.com | ||
+ | Redirect permanent / https:// | ||
+ | </ | ||
+ | If you only redirect, you dont even need a document root. | ||
+ | </ | ||
+ | |||
+ | You can also use **modrewrite**, | ||
+ | |||
+ | <file apache> | ||
+ | < | ||
+ | [...] | ||
+ | < | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTPS} off | ||
+ | RewriteRule (.*) https:// | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | And don't forget to restart Apache. |
apache/setting_up_hsts_in_apache.1575044367.txt.gz · Last modified: 2020/07/15 09:30 (external edit)