【问题标题】:Share assets folder between two subdomain's document roots在两个子域的文档根目录之间共享资产文件夹
【发布时间】:2021-06-04 13:28:36
【问题描述】:

我有两个网络应用程序共享相同的资产(js、css、img 等),但使用不同的子域/文档根目录。

我试图弄清楚如何在两个文档根目录之间共享一个资产文件夹,这样我就可以避免在对资产应用更改后必须更改每个子域的资产文件夹。

感谢您的宝贵时间。

当前结构:

www/html
    ├─ subdomain1
    │   └─ assets
    │   └─ index.php
    └─ subdomain2
        └─ assets
        └─ index.php

所需结构:

www/html
    ├─ assets
    ├─ subdomain1
    │   └─ index.php
    └─ subdomain2
        └─ index.php

VHost Confs:

子域一:

<VirtualHost *:80>
  ServerName www.one.mydomain.com
  ServerAlias one.mydomain.com
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html/subdomain1/

<Directory /var/www/html/subdomain1/>
   Options -Indexes +FollowSymLinks
   AllowOverride All
   DirectoryIndex index.php
</Directory>

  ErrorLog /var/www/html/logs/subdomain1-error.log
  CustomLog /var/www/html/logs/subdomain1-access.log combined
</VirtualHost>

子域二:

<VirtualHost *:80>
  ServerName www.two.mydomain.com
  ServerAlias two.mydomain.com
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html/subdomain2/

<Directory /var/www/html/subdomain2/>
   Options -Indexes +FollowSymLinks
   AllowOverride All
   DirectoryIndex index.php
</Directory>

  ErrorLog /var/www/html/logs/subdomain2-error.log
  CustomLog /var/www/html/logs/subdomain2-access.log combined
</VirtualHost>

【问题讨论】:

    标签: php apache centos subdomain virtualhost


    【解决方案1】:

    在第二台主机的配置中,您可以使用 Apache 的 mod_alias 定义“主”资产目录的别名:

    <VirtualHost *:80>
        ServerName www.two.mydomain.com
        ...
        <Location "/assets">
            Alias "/var/www/html/subdomain1/assets"
        </Location>
    

    然后只需删除重复的目录/var/www/html/subdomain2/assets

    或者,您可以保持配置不变,删除第二个目录,然后符号链接到第一个:

    mv /var/www/html/subdomain2/assets /var/www/html/subdomain1/assets.old
    ln -s /var/www/html/subdomain1/assets /var/www/html/subdomain2
    

    但是请注意,这两种方法都可能使部署/开发变得棘手,因为您实际上是在将它们锁定为始终具有相同文件的相同版本。最终,最好将它们保留为重复项,而是解决您的部署机制。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多