我的httpd-vhosts.conf文件中有子域的以下配置:
<VirtualHost *:80>
ServerAdmin foo@bar.com
DocumentRoot "/home/www"
ServerName bh.dev
ServerAlias *.bh.dev
ErrorLog "/var/log/apache2/bh-error_log"
CustomLog "/var/log/apache2/bh-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/srv/www/htdocs"
ServerName blog.bh.dev
ErrorLog "/var/log/apache2/bh-error_log"
CustomLog "/var/log/apache2/bh-access_log" common
</VirtualHost>
bh.dev 和 bh.dev/blog 网址已成功显示,但 blog.bh.dev 则未成功显示。有什么问题?
提前谢谢你。
答案 0 :(得分:0)
blog.bh.dev
请求由第一个定义本身处理,因为它也符合bh.dev
条件。因此,将第二个虚拟主机定义置于第一个虚拟主机定义之上可以解决问题。
<VirtualHost *:80>
DocumentRoot "/srv/www/htdocs"
ServerName blog.bh.dev
ErrorLog "/var/log/apache2/bh-error_log"
CustomLog "/var/log/apache2/bh-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin foo@bar.com
DocumentRoot "/home/www"
ServerName bh.dev
ServerAlias *.bh.dev
ErrorLog "/var/log/apache2/bh-error_log"
CustomLog "/var/log/apache2/bh-access_log" common
</VirtualHost>
作为一般规则,我总是将更具体的定义置于更通用的定义之上。