[精讚] [會員登入]
1395

[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] 自訂錯誤頁面及移掉歡迎頁 Apache 有一個歡迎頁,以正式網站來說,出現這頁有點不專業,該移除它..

[Centos7] 解決資安的幾個問題 因為資安的關係,接到了一些弱點掃描出現的問題,解決方法做個整理。

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

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

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

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

[jQuery] 利用load()來達成ajax的寫法 jQuery中利用load()來達成ajax的寫法,也有人稱他是假的ajax,作法就是..

沒有非誰做不可的事,也沒有不可被取代的人 沒有非誰做不可的事,也沒有不可被取代的人

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

PHP for sphinx 函式庫安裝 PECL/sphinx PHP>= 5.2.2 已經能原生支援 sphinx,可是預設的沒有裝,我們得自己裝才能用

[Windows7] 移除IE10及移除IE11 Windows7 不得已的情況要移除IE11或IE10怎麼做?