[精讚] [會員登入]
1404

[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] 利用.htaccess防盜圖 利用.htaccess防盜圖,同時也介紹一個產生防盜圖.htaccess檔的網站

APACHE的記錄檔格式 LogFormat 語法 在APACHE中有定義一些記錄的語法模版 在 /etc/httpd/conf/httpd.conf 中: LogForm

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

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

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

[APACHE] 關於RewriteCond $1 RewriteCond $1的意義和解釋

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

為什麼要買長達二十年的保單? 為什麼要買長達二十年的保單?找一個可以說服我買二十年保單的理由。

[jQuery] select 元件的取值及給值 html中的元件select,在jquery中要如何使用?

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

世紀帝國征服者新版本--被遺忘的帝國 世紀帝國征服者新版本--被遺忘的帝國 世紀二代的征服者是精典遊戲中的精典,aofe更好玩...

APACHE的記錄檔格式 LogFormat 語法 在APACHE中有定義一些記錄的語法模版 在 /etc/httpd/conf/httpd.conf 中: LogForm