【问题标题】:What is the procedure to add domain aliases to an existing linux apache installation?将域别名添加到现有 linux apache 安装的过程是什么?
【发布时间】:2014-02-24 05:17:33
【问题描述】:

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

当我想添加一个新域时,我在/etc/hosts 中创建一个127.0.0.1 test.com *.test.com 行,在/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中的不同文件夹。我如何做到这一点?

【问题讨论】:

    标签: apache ubuntu virtualhost vps


    【解决方案1】:

    每个VirtualHost 容器只能存在一个DocumentRoot。由于您为每个aaa.test.combbb.test.com 等指定了不同的DocumentRoot,因此您需要为每个VirtualHost 设置一个单独的VirtualHost

    <VirtualHost *:80>
        ServerName aaa.test.com
        DocumentRoot /var/www/aaa
        DirectoryIndex index.php index.html
        ...
    </VirtualHost>
    

    等等。

    【讨论】:

    • 就是这样... Greb :)
    【解决方案2】:

    由于 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 做同样的事情。这就是你需要做的所有事情......一切都最好:)

    【讨论】:

    • 域名服务器呢?我要为 aaa 添加一个 cname 吗?
    • nameservers 和 cname 记录与 DNS 相关,与 apache webserver 无关。这取决于该域在何处注册以及应如何解析。此外,名称服务器总是为主域而不是子域添加。让我知道您对 DNS 的确切要求,以便我可以为您提供帮助。 :)
    • 我想要完全设置一个新域,您必须创建一个指向 DNS 主机的 A 记录。谢谢
    • 是的,正是你需要的……但是 apache 与设置 DNS 无关。
    猜你喜欢
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多