简体   繁体   English

在apache 2.4版中配置子域。*

[英]configure a subdomain in apache version 2.4.*

I have the following configuration for subdomain in my httpd-vhosts.conf file: 我在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>

The bh.dev and bh.dev/blog URLs are successfully displayed, but blog.bh.dev is not. 已成功显示bh.devbh.dev/blog URL,但没有显示blog.bh.dev What is the problem? 问题是什么?

Thank you in advance. 先感谢您。

blog.bh.dev request is handled by the first definition itself as it also qualifies to be under bh.dev . blog.bh.dev请求由第一个定义本身处理,因为它也符合bh.dev下的bh.dev So placing the second virtual host definition above the first one would solve the problem. 因此,将第二个虚拟主机定义放在第一个之上可以解决该问题。

<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>

As a general rule, I always place more specific definitions above the more generic ones. 通常,我总是将更具体的定义放在更通用的定义之上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM