Drupal 錯誤警告:Trusted Host Settings 的安全性修正與設定


第一次在伺服器[1]安裝「Drupal 內容管理系統(Content Management System)」後出現一個錯誤警告,內容表示在網站在基本安裝中有一項功能「Trusted Host Settings」尚未啟用,導致網站在使用時容易有資訊安全上的風險疑慮。

該錯誤提示可以在「http://SAMPLE.com/admin/reports/status」頁面中找到,警告內容如下(如 Fig.1):

Trusted Host Settings 未啟用
The trusted_host_patterns setting is not configured in settings.php. This can lead to security vulnerabilities. It is highly recommended that you configure this. See Protecting against HTTP HOST Header attacks for more information.

Fig.1, Drupal's Error Message: "Trusted Host Settings".
Fig.1, Drupal’s Error Message: “Trusted Host Settings”.

為了解決這個問題,我們需要重新設定「setting.php」。該檔案存放在 Drupal 安裝目錄下的「/sites/default」目錄中。以我自己架設的 Linux 系統為例,真實檔案路徑為「$public_html/sites/default/」。

這次新安裝的版本是最新的 Drupal 8.x,可以在該目錄中直接發現 setting.php 這個檔案並逕自修改。

Linux 指令提示:複製並修改檔案名稱指令為「sudo cp OLD_FILE_NAME.php NEW_FILE_NAME.php」。

要是你沒找到相同的檔案,也應該會在同一個目錄下發現「default.settings.php」。只要簡單的複製該檔案並修改名稱為 setting.php 就能完成檔案的建置。

接下來,我們只要把下面指令敘述寫入 setting.php 中(需貼在 <?php 之後),就能消除 Drupal 的錯誤警告,在 Drupal 系統與伺服器之間建立安全的內連結,藉以加強我們網站的安全性。

$settings['trusted_host_patterns'] = array(
'^vedfolnir\.com$',
'^www\.vedfolnir\.com$',
'^localhost$',
);

備註:指令敘述中的「vedfolnir」字樣,請自行替換成你個人的網域名稱(Domain Name)。

伺服器推薦Bluehost 伺服器供應商

分享這篇文章:

作者:

發表時間:

修改日期:

使用 Email 訂閱 最新消息不漏接

我們尊重您的隱私,隨時可取消訂閱。

留言

在〈Drupal 錯誤警告:Trusted Host Settings 的安全性修正與設定〉中有 1 則留言

  1. 「phillippdallas」的個人頭像
    phillippdallas

    Heey There. I found your blpog usong msn. Thiis iss a really weell witten article.
    I wjll mske sure tto bookmark itt annd come bacfk
    too rad extrta of your heslpful info. Thank youu ffor the
    post. I’ll definitely comeback.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *