Drupal 8/Drupal 9配置文件settings.php进阶

Submitted by admin on Wed, 06/30/2021 - 11:04

Drupal http client使用代理抓取墙外数据

$settings['http_client_config']['proxy']['http'] = 'http://206.189.127.27:8080';
$settings['http_client_config']['proxy']['https'] = 'http://206.189.127.27:8080';
$settings['http_client_config']['verify'] = false;
$settings['http_client_config']['proxy']['no'] = ['127.0.0.1', 'localhost'];

错误显示设置和调试设置

$config['devel.settings']['devel_dumper'] = 'var_dumper';
$config['system.logging']['error_level'] = 'verbose';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

proxy

$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = [  $_SERVER['REMOTE_ADDR'],];

跳转

$bad_bots = [
    'YisouSpider',
    'MQQBrowser',
    'Mb2345Browser',
    'LieBaoFast',
    'UCBrowser'
];
foreach ($bad_bots as $bad_bot) {
  if (str_contains($_SERVER['HTTP_USER_AGENT'], $bad_bot)) {
    header('HTTP/1.0 403 Forbidden');
    print $bad_bot . ' Not allowed, bad visit!!';
    exit;
  }
}

强制HTTPS(Drupal 7)

$_SERVER['HTTPS'] = 'on';  
$_SERVER['SERVER_PORT'] = 443;