我有一个在 * 中托管的个人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.php
,bbb.test.com
指向/var/www/bbb/index.php
。总结一下,不同的别名 - 相同的域 - 不同的文件夹都在apache中。我如何实现这一目标?
答案 0 :(得分:2)
每个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>
:
{{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做同样的事情..这就是你要做的所有事情......最好的一切:)