pantheon-systems / pantheon_domain_masking
Drupal 8 的域名遮蔽中间件
Requires (Dev)
- drupal/coder: ^8.3
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-23 18:28:01 UTC
README
此模块允许在Drupal 8中实现域名遮蔽,适用于Drupal不在Apache下运行或托管配置不可用的情况。
通常,通过在.htaccess
或nginx.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.io
和 https://live-example-b.pantheonsite.io
。导航到 https://www.example.com/user/login
将解析为边缘服务器为该请求选择的任何后端,并且根据配置(例如轮询)可能不会在请求之间保持一致。为了直接管理 A
和 B
站点,需要在两个网站上都将“允许平台域访问?”字段设置为“是”,并且内容管理员需要直接访问 https://live-example-a.pantheonsite.io/user/login
或 https://live-example-b.pantheonsite.io/user/login
来管理这些特定实例。