将域别名添加到现有linux apache安装的过程是什么?

时间:2014-01-31 13:30:07

标签: apache ubuntu virtualhost vps

我有一个在 * 中托管的个人VPS和一个ubuntu安装。 ubuntu运行apache,php,mysql,目前用于虚拟主机映射的5个网站。我正在编写整个程序以防有人需要它。

当我想添加新域时,我在127.0.0.1 test.com *.test.com中创建了一个/etc/hosts行,在/etc/apache2/sites-availablerun a2ensite test.com中添加了一个新文件 - 然后重新启动apache。每个网站在/var/www中都有自己的文件夹,虚拟主机条目如下所示:

<Virtualhost *:80>

      # Admin email, Server Name (domain name) and any aliases
      ServerAdmin info@test.com
      ServerName  www.test.com
      ServerAlias test.com *.test.com

      # Index file and Document Root (where the public files are located)
      DirectoryIndex index.html index.php
      DocumentRoot "/var/www/test.com"
      <Directory /var/www/test.com>
          Options FollowSymLinks
          AllowOverride All
          Order allow,deny
          allow from all
      </Directory>  
</Virtualhost> 

我打算添加一些别名,例如aaa.test.combbb.test.comccc.test.com等,这些别名将指向/转发到不同的文件夹。 aaa.test.com一个将指向/var/www/aaa/index.phpbbb.test.com指向/var/www/bbb/index.php。总结一下,不同的别名 - 相同的域 - 不同的文件夹都在apache中。我如何实现这一目标?

2 个答案:

答案 0 :(得分:2)

每个DocumentRoot容器只能存在一个VirtualHost个容器。由于您为每个DocumentRootaaa.test.com等指定了不同的bbb.test.com,因此您需要为每个VirtualHost设置单独的<VirtualHost *:80> ServerName aaa.test.com DocumentRoot /var/www/aaa DirectoryIndex index.php index.html ... </VirtualHost>

{{1}}

等等。

答案 1 :(得分:1)

由于aaa.test.com和bbb.test.com应指向不同的目录,因此您需要手动创建单独的Virtualhost条目。在此之前,您必须从test.com Virtualhost 条目的 ServerAlias 中删除_ * .test.com_。然后在 / etc / apache2 / sites-available 创建一个文件,比如 aaa.test.com 并添加以下内容然后保存

<Virtualhost *:80>

  ServerName  aaa.test.com
  DirectoryIndex index.html index.php
  DocumentRoot "/var/www/aaa/"

</Virtualhost>

确保重新启动/重新加载apache服务。

为bbb.test.com做同样的事情..这就是你要做的所有事情......最好的一切:)