pantheon-systems/pantheon_domain_masking

Drupal 8 的域名遮蔽中间件

2.0.1 2023-03-14 15:20 UTC

README

Unofficial

此模块允许在Drupal 8中实现域名遮蔽,适用于Drupal不在Apache下运行或托管配置不可用的情况。

通常,通过在.htaccessnginx.conf文件中添加几行代码即可实现域名遮蔽;然而,如果该方法不可用,此模块允许Drupal意识到主机变更,并在生成重定向时持久化这些变更。

安装模块

可以通过下载此模块并将其直接放置在modules/contrib(或您决定在文件系统中存储模块的任何位置)中来安装此模块。您还可以通过运行以下命令使用composer安装安装

composer require pantheon-systems/pantheon_domain_masking

启用和配置模块

一旦将模块安装到文件系统中,就可以像其他任何贡献模块一样启用它。但是,这不会启用域名遮蔽功能。一旦模块处于活动状态,模块的配置页面(/admin/config/pantheon-domain-masking/options)将允许您输入公共域名。您需要在此页面上切换启用域名遮蔽?字段以启用中间件。

或者,您可以在settings.php文件(或由settings.php导入的另一个文件)中配置模块,使用Drupal的配置覆盖系统。在settings.php中指定值如下

$config['pantheon_domain_masking.settings']['domain'] = 'foo.com';
$config['pantheon_domain_masking.settings']['subpath'] = 'bar';

当您加载配置页面时,您会发现您在settings.php中设置的选项出现在表单中,并且表单输入被禁用。

可用的配置覆盖

  • domain: 公共域名。
  • subpath: Drupal的子路径。不要包含前导/
  • allow_platform: 允许平台访问。

缓存上下文

如果启用了allow_platform,则需要将url.site添加到renderer.config.required_cache_context中(位于sites/default/services.yml),以防止在平台域名中预加载缓存并在公共域名中提供,反之亦然。

  renderer.config:
    # Renderer required cache contexts:
    #
    # The Renderer will automatically associate these cache contexts with every
    # render array, hence varying every render array by these cache contexts.
    #
    # @default ['languages:language_interface', 'theme', 'user.permissions']
    required_cache_contexts: ['url.site', 'languages:language_interface', 'theme', 'user.permissions']

示例

假设一个网站运行在Pantheon上,其实时环境地址为https://live-example.pantheonsite.io。假设您想使用的公共域名是https://www.example.com。在这种情况下,您需要在公共域名:字段中输入www.example.com。一旦将启用域名遮蔽?字段设置为,Drupal将使用www.example.com生成任何内部重定向。

允许平台访问

在正常情况下,此模块将强制所有请求使用遮蔽域名。但是,如果您想通过Pantheon的平台域名(以.pantheonsite.io结尾)访问此网站而不通过遮蔽域名,请将允许平台域名访问?字段设置为

示例

根据上面的示例,假设公开域正在遮盖两个不同的Pantheon环境,例如 https://live-example-a.pantheonsite.iohttps://live-example-b.pantheonsite.io。导航到 https://www.example.com/user/login 将解析为边缘服务器为该请求选择的任何后端,并且根据配置(例如轮询)可能不会在请求之间保持一致。为了直接管理 AB 站点,需要在两个网站上都将“允许平台域访问?”字段设置为“是”,并且内容管理员需要直接访问 https://live-example-a.pantheonsite.io/user/loginhttps://live-example-b.pantheonsite.io/user/login 来管理这些特定实例。