承接 drunomics/multisite-request-matcher 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

drunomics/multisite-request-matcher

Composer 安装命令:

composer require drunomics/multisite-request-matcher

包简介

Matches requests to multisite hosts.

README 文档

README

Matches requests to multisites based upon configuration driven by environment variables. The packages works well with symfony/dotenv and symfony/http-foundation as used by drupal/core.

The multisite setup supports configuration via a common base-domain ($APP_MULTISITE_DOMAIN) or via per site domains. Via environment-dependent variables the common base-domain may be enabled for preview environments only also. The configured default site is used when the common multisite base-domain is accessed without any suiting prefix. Next, it's used for CLI invocations if no SITE variable is given a.

Installation

composer require drunomics/multisite-request-matcher

Configuration

The package support construction site URLs via via a common base-domain ($APP_MULTISITE_DOMAIN) or via per site domains. Optional, site variants like "admin" or "api" are supported - useful if the app uses multiple hosts for things like the admin interface or an API endpoint.

That can be used to construct URLs like the following:

  • Commom multisite domain:

      https://site-a_stage.example.com
      https://site-b_stage.example.com
    
  • Per site domains:

      https://www.site-a.com
      https://wwww.site-b.com
    
  • Common multisite domain with variants:

      https://api--site-a_stage.example.com
      https://api--site-b_stage.example.com
      https://admin--site-a_stage.example.com
      https://admin--site-b_stage.example.com
    
  • Per site domains with variants:

      https://api.site-a.com
      https://api.site-b.com
      https://admin.site-a.com
      https://admin.site-b.com
    

The following environment variables may be set to configure the request matcher:

Variable name Required Example Value Description
TRUSTED_PROXIES No 127.0.0.1 A list of IP addresses or subnets, separated by space.
HEADER_FORWARDED_HOST No X_FORWARDED_HOST A non-standard value for the host header.
APP_SITES Yes site-a site-b The list of site names, separated by space. May contain lowercase characters and dashes only.
APP_DEFAULT_SITE No site-a The default site to set. If not set, the first set will be set by default.
APP_SITE_VARIANTS No admin api An optional list of variants; i.e. variants of the same site.
APP_SITE_VARIANT_SEPARATOR No -- The separator between the variant name and the host, defaults to "--".
APP_MULTISITE_DOMAIN ~ stage.codebase.dev A common base domain for all sites. Required when multisite base domains should be used.
APP_MULTISITE_DOMAIN_PREFIX_SEPARATOR No _ The separator between the site name and the common multisite base domain. Defaults to '_'.
APP_SITE_DOMAIN__{{ SITE }} ~ site-a.com The per-site domain - required when per-site domains should be used. One variable per site must be provided with dashes replaced to underscores, e.g. for site-a the variable name would be APP_SITE_DOMAIN__site_a
APP_SITE_DOMAIN_ALIASES__{{ SITE }} No site-a.hoster.com,site-a.hoster.com Comma separated, per-site domain aliases that are allowed in addition to the main domain. Useful when access should be allowed via some non-primary domains also; e.g., when behind a CDN. One variable per site must be provided with dashes replaced to underscores, e.g. for site-a the variable name would be APP_SITE_DOMAIN_ALIASES__site_a
APP_SITE_DOMAIN ~ site-a.com If an environment is bound to a fixed site, the site's domain. Requires SITE to be predefined.
APP_SITE_DOMAIN_ALIASES No site-a.host.com,site-a.host2.com If an environment is bound to a fixed site, the site's domain aliases (see above). Requires SITE to be predefined.

Results

  • The matched host is set as trusted host to the symfony/http-foundation request API via trusted host patterns.
  • The following environment variables are set:
Variable name Example Value Description
SITE site-a The active site.
SITE_VARIANT api The active site variant. Empty if no variant is active.
SITE_HOST api--site-b_stage.example.com The site's full host for the active site and variant.
SITE_MAIN_HOST stage.example.com The site's main host, without any variant.

CLI invocations

In order to make the same environment variables available for CLI invocations, the package provides the binary request-matcher-site-variables which outputs them based upon the set $SITE variable. Site variants are not supported in CLI requests, thus SITE_VARIANT is is always empty.

Usage with Drupal

  • Best, invoke the request matcher via the composer autoloader; that makes sure it is invoked very early and has matched requests before anything else goes on. For an example refer to this

    Be sure your environment variables are set and invoke it like that:

    $site = drunomics\MultisiteRequestMatcher\RequestMatcher::getInstance()
      ->match();
    
  • Add the following line to Drupal's sites.php such that Drupal can pick up the matched site. The site name of the APP_SITES variable should match the Drupal site directory names:

    $sites[$request->getHost()] = getenv('SITE');
    
  • Remove any trusted host patterns from Drupal as the request matcher already checked it.

Credits

developed by drunomics GmbH, hello@drunomics.com Please refer to the commit log individual contributors.

drunomics/multisite-request-matcher 适用场景与选型建议

drunomics/multisite-request-matcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.69k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 drunomics/multisite-request-matcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 drunomics/multisite-request-matcher 我们能提供哪些服务?
定制开发 / 二次开发

基于 drunomics/multisite-request-matcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-18