You are here

Nginx下如何将Drupal 8/9 部署在一个域名的子目录下面

g089h515r806 的头像
Submitted by g089h515r806 on 星期四, 2021-01-14 02:27

作者:亚艾元技术部

Apache默认就可以方便的放在子目录下面,但是nginx下面怎么配置,我们研究了一下,发现这是可行的。

 

建立软连接,

ln -s /var/www/example subdirectory

 

配置Nginx:

location @subsite {
    try_files $uri /subdirectory/index.php?$query_string;
  }
 
  location = /subdirectory/ {
    alias /var/www/example/;  
    index index.php;
  }
  location /subdirectory/ {
     try_files $uri $uri/ @subsite;
  }

 

当location等于/subdirectory/,我开始使用try files,直接获取index.php,开始有问题,直接下载了index.php文件,后台改了一下,但是Drupal生成的URL路径,不会带有subdirectory子目录,在首页。

  location = /subdirectory/ {
    alias /var/www/example/;  
    index index.php;
  }

 

这里的别名解决了这个问题。

 

修改站点的html里面的路径,还有CSS部分的,增加子目录支持。


论坛:

Drupal版本: