【问题标题】:Multiple versions of a website each with its own root directory using Apache使用 Apache 的网站的多个版本,每个版本都有自己的根目录
【发布时间】:2011-07-09 12:54:08
【问题描述】:

我的网站有多个版本。每个都驻留在自己的文件夹中,例如:

site_v1/  
  index.html  
  page1.html    

site_v2/  
  index.html  
  page1.html  

如何配置 apache 让网站的每个版本都有自己的根目录定义?

换句话说,我想让site_v1/index.html认为根目录是site_v1,而site_v2/index.html认为根目录是site_v2

【问题讨论】:

    标签: apache web directory root


    【解决方案1】:

    您正在寻找VirtualHost 指令。

    Apache manual on virtual hosts

    【讨论】:

      【解决方案2】:

      正如@Pekka 所写,您确实在寻找VirtualHost 指令,但我可能会为您的虚拟主机配置添加一个示例配置。这应该放在您的httpd.conf 文件中,根据您的喜好进行编辑,并记住填写完整路径:

      NameVirtualHost v1.yoursite.com:80
      <VirtualHost v1.yoursite.com:80>
          ServerName v1.yoursite.com
          ServerAlias v1.yoursite.com
          DocumentRoot /path/to/site_v1
          ErrorLog /path/to/prefered/error.log
          CustomLog /path/to/prefered/access.log combined
          <Directory /path/to/site_v1>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride None
              Order allow,deny
              Allow from all
          </Directory>
      </VirtualHost>
      
      NameVirtualHost v2.yoursite.com:80
      <VirtualHost v2.yoursite.com:80>
          ServerName v2.yoursite.com
          ServerAlias v2.yoursite.com
          DocumentRoot /path/to/site_v2
          ErrorLog /path/to/prefered/error.log
          CustomLog /path/to/prefered/access.log combined
          <Directory /path/to/site_v2>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride None
              Order allow,deny
              Allow from all
          </Directory>
      </VirtualHost>
      

      如果您愿意,您可以选择为您网站的每个版本使用不同的访问/错误日志。只需更改日志文件的名称/路径,就完成了。 /path/to 是站点文件夹的路径,应将 v1.yoursite.com 和 v2.yoursite.com 更改为您要用于每个版本的相对域。如果您不想更改日志文件,请删除 ErrorLogCustomLog 指令,我将默认使用 httpd.conf 中设置的主日志文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-02
        • 2015-04-04
        • 2019-10-12
        • 1970-01-01
        • 2023-04-04
        • 2018-06-07
        相关资源
        最近更新 更多