[精讚] [會員登入]
2112

[APACHE] Centos7,8設定 HSTS ( HTTP Strict Transport Security )

CENTOS7,CENTOS8 資安上需要設定的 HSTS的方法。

分享此文連結 //n.sfs.tw/15373

分享連結 [APACHE] Centos7,8設定 HSTS ( HTTP Strict Transport Security )@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
最後編修
2021-09-07 16:36:59 By 張○○
 

自動目錄

這近資安要求有https的服務來取代http,雖然我覺得大部分的網站都沒必要弄https,但是網路是由錢來推動的,安全只是一個愰子。

一般有https的網站,都還是會提供http的服務,再藉由轉址或是重寫的方法轉成https。

如果希望一開始就嘗試建立 https 連線,那麼就讓你的apache一開始就送一個httpd 的header 告訴瀏覽器說請他用https來連。

這就是 HSTS ( HTTP Strict Transport Security )。

簡單來說 HSTS 是希望一開始就建立 https 連線。

查看支援模組

# apachectl -M | grep 'header'
 headers_module (shared)  <== 預設有安裝

如果沒有出現 headers_module 的話,請設定[2]:/etc/httpd/conf.modules.d/00-base.conf  加入這一行:

LoadModule headers_module modules/mod_headers.so

重啟 apache

寫入header

全域

# vi /etc/httpd/conf/httpd.conf

在尾端加入,31536000那串數字是一年

Header always set Strict-Transport-Security "max-age=31536000;includeSubdomains; preload"

重啟apache

單網站

加在你的virtual host設定中,例如

<VirtualHost *:80>
    DocumentRoot /path/to
    ServerName example.com
    Header always set Strict-Transport-Security "max-age=3153600;includeSubdomains; preload"
    ...
</VirtualHost>

同時 443埠的服務也要設定,你的 ssl.conf

<VirtualHost _default_:443>
    Header always set Strict-Transport-Security "max-age=3153600;includeSubdomains; preload"
    ...
</VirtualHost>

理論上 80埠有設就可以,但這樣的話檢測不過,因此 443埠的部分也記得要設定

重啟apache

測試

使用CURL

# curl -s -D- https://example.com/ | grep -i Strict
Strict-Transport-Security: max-age=3153600;includeSubdomains; preload

# curl -s -D- http://example.com/ | grep -i Strict
Strict-Transport-Security: max-age=3153600;includeSubdomains; preload

以上有顯示代表成功

使用網站

1. https://www.ssllabs.com/ssltest/

2. https://check.twnic.tw/

twnic的比較兩光,不過速度比較快。

 

參考資料

[1] https://blog.camel2243.com/2016/05/13/apache-apache-%E8%A8%AD%E5%AE%9A-hsts-http-strict-transport-security/

[2] https://forums.centos.org/viewtopic.php?t=57035

[3] https://www.namecheap.com/support/knowledgebase/article.aspx/9711/38/how-to-check-if-hsts-is-enabled/

END

你可能感興趣的文章

[Apache] 顯示或不顯示錯誤 php預設錯誤不顯示,有三種方法可以顯示或不顯示錯誤

強迫網頁預設編碼語系 大部分的瀏覽器如果編碼設成「自動偵測」時都能正確的分析。但世界並不會這麼平順完美,明明我這樣設定utf8他就是用big5丟出來...

UTF-8的網頁但IE8一片空白 UTF8編碼的網頁在Firefox 正常顯示、但IE8 就是空白,IE8編碼設定是「自動偵測」可是自動偵測到的是 big5...

PHP 7.0 升級到 PHP7.3 因為套件的關係,想把PHP7.0升到7.3 結果又退回原版本

[APACHE] Centos7,8設定 HSTS ( HTTP Strict Transport Security ) CENTOS7,CENTOS8 資安上需要設定的 HSTS的方法。

[Apache] 利用.htaccess防盜圖 利用.htaccess防盜圖,同時也介紹一個產生防盜圖.htaccess檔的網站

隨機好文

Smarty安裝 smarty 是著名的樣版引擎,非常的好用,用多了突然發現拿掉smarty反而不會寫php了,以下是安裝過程..

對物品的感情 這個議題很奇怪,可是大部分的人都會有,物品是死的,壞了就淘汰,出新的就被替換。為何會有情感?

McJob 淺談 在英語世界裡,近期多了一個英文生字 Mcjob,定義為「低薪、無聊且沒有什麼前景的工作」。

[MariaDB] Centos 7安裝mariadb + apache + php + phpmyadmin Centos 7安裝mariadb+apache+php+phpmyadmin

被動收入與財富自由 增加被動收入很困難,要達到財富自由更不容易,看看我怎麼說