2017-11-26

Drupal8,インストール,トラブル解決法 その2

環境

OS : Linux Mint18
ソフト名 : Drupal8
データベース : Sqlit3

見つかったエラー
─────────────────────────────
信頼の置けるホストの設定

無効
settings.php の trusted_host_patterns が設定されていません。そのため、セキュリティ面で脆弱となるかもしれません。設定することを強くおすすめします。より詳しい情報は、HTTP HOST ヘッダー攻撃への防御を参照してください。
─────────────────────────────








解決方法

指定ファイルの内容を一部書き換える。

▶ settings.php

* $settings['trusted_host_patterns'] = array(
*   '^example\.com$',
*   '^.+\.example\.com$',
*   '^example\.org$',
*   '^.+\.example\.org$',
* );


上記の内容を対処方法(1)〜(4) のいずれかに書き換える。(736行目当たり)

対処方法 (1) ---> http://localhost/サイト名

▶ sites/default/settings.php

$settings['trusted_host_patterns'] = [
 '^localhost$',
 ];


自身のサーバであれば、  '^localhost$', が含まれていれば問題ない。


対処方法 (2) ---> http://localhost
▶ sites/default/settings.php

Trusted host security setting in Drupal 8.4.0 and PHP 7.1.8 for XAMP

To enable the trusted host mechanism, we need to enable our allowable hosts
 in $settings['trusted_host_patterns'].

Open the "settings.php" file and update the below code to Enable the Trusted host setting:

$settings['trusted_host_patterns'] = array(
 '^localhost$',
 '^192\.168\.00\.52$',
 '^127\.0\.0\.1$',
);


自身のサーバーの場合。



対処方法 (3) ---> http://www.example.com

▶ ファイル名 sites/default/settings.php


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

自身のサーバから、公開用のサーバにコピーする場合。
自身のサーバー http://localhost/www.example.com でテストし、
公開するURLが http://www.example.com の時。



対処方法 (4) ---> http://drupal8

▶ sites/default/settings.php

$settings['trusted_host_patterns'] = [
  '^drupal8$',
];

http://drupal8 で公開する場合。

以上。