gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:58:09 24 4
gpt4 key购买 nike

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

当我想添加一个新域时,我创建了一个 127.0.0.1 test.com *.test.com排入 /etc/hosts , 在 /etc/apache2/sites-available 中添加一个新文件和 run 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.com , bbb.test.com , ccc.test.com等,这将指向/转发到不同的文件夹。 aaa.test.com一个会指向 /var/www/aaa/index.phpbbb.test.com/var/www/bbb/index.php .总而言之,不同的别名 - 相同的域 - apache中的不同文件夹。我如何做到这一点?

最佳答案

只能存在一个DocumentRoot根据 VirtualHost容器。由于您指定了不同的 DocumentRoot对于每个 aaa.test.com , bbb.test.com等,您需要设置一个单独的VirtualHost对于每个:

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

等等。

关于apache - 将域别名添加到现有 linux apache 安装的过程是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21481303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com