首页 > 解决方案 > Drupal 多站点设置与 NIGNX 中的子目录

问题描述

我正在使用带有多站点设置的 Drupal 8,位于“/var/www/html/drupal”目录中,并且我使用 NGINX 作为 Web 服务器。

我有以下域名:

  1. qa.example.com
  2. qa.example.com/v1
  3. qa.example.com/v2

其中“qa.example.com”是提供静态文件的主要域(index.html 中包含一些信息)。v1 和 v2 是使用 Drupal 8 Multi-site 创建的动态站点。

由于 qa.example.com 只有 1 个静态文件,我将它放在 Drupal Core 目录中,并将虚拟主机指向“/var/www/html/drupal”目录。根据examples.sites.php中提供的文档,我在sites.php中添加了站点条目,如下所示:

<?php
  $sites['qa.example.com.v1'] = 'v1.example.com';
  $sites['qa.example.com.v2'] = 'v2.example.com';

访问“qa.example.com”时它工作正常,因为它只有一个 index.html 文件,但访问“qa.example.com/v1”时,我被重定向到“qa.example.com/core/ install.php”或收到“404 Not Found”nginx 页面。我不明白我错过了什么。

以下是我正在使用的 NGINX 配置:

server {
  server_name qa.example.com;
  listen 80;
  listen [::]:80;
  index index.php index.html;

  location / {
    root /var/www/html/drupal;
    try_files $uri /index.php?$query_string;
  }

  location /v1 {
    root /var/www/html/drupal;
    # try_files $uri $uri/ /var/www/html/drupal/index.php?$query_string;
  }

  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }
  location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }
  location ~ \..*/.*\.php$ {
    return 403;
  }
  location ~ ^/sites/.*/private/ {
    return 403;
  }
  location ~ (^|/)\. {
    return 403;
  }
  location @rewrite {
    rewrite ^/(.*)$ /index.php?q=$1;
  }
  location ~ '\.php$|^/update.php' {
    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }
  location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;
  }
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
  }
}

以下是我的目录结构:

// main directory
/var/www/html/drupal

// my static file for landing domain name
/var/www/html/drupal/index.html

// drupal core files
/var/www/html/drupal/core
// drupal's index.php file
/var/www/html/drupal/index.php
// contrib and custom modules
/var/www/html/drupal/modules

// Site v1 directory as per Drupal's multi-site directory structure.
/var/www/html/drupal/sites/v1
// Site v2 directory as per Drupal's multi-site directory structure.
/var/www/html/drupal/sites/v2

我在网上查看了许多参考资料,但没有任何效果。

注意:v1v2不是实际目录“/var/www/html/drupal”。

以下是我提到的链接:

  1. 子文件夹中的 nginx 项目
  2. Nginx 位置配置(子文件夹)
  3. 多站点,两个站点共享同一个域?
  4. Nginx 子目录中的 PHP 应用程序

标签: phpnginxdrupal-8multisite

解决方案


由于您正在处理多站点设置,所以我建议您在站点目录中创建带有域名的目录,然后像下面那样进入 sites.php。

$sites[directoy name] = 'domain name';

对于每个站点,您需要在sites.php 中进行条目。每个域都应该有 settings.php。


推荐阅读