VirtualHost 是否指向同一个 DocumentRoot?

VirtualHost 是否指向同一个 DocumentRoot?

由于某种原因,domain1.org 和 domain2.org 都指向 /var/www,我是不是漏掉了什么?Apache2 错误日志也干净吗?我就是搞不懂。这应该是一个简单的虚拟主机

<VirtualHost *:80>

    ServerName domain1.org
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/

    <Directory /var/www/>
        DirectoryIndex index.php        
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

<VirtualHost *:80>

    ServerName domain2.org
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/wordpress-1/

    <Directory /var/www/wordpress-1/ >
        DirectoryIndex index.php        
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

答案1

您的 VirtualHost 定义似乎没有任何问题。更新配置文件后,您是否记得重新启动 apache?您没有说明您使用的是哪种操作系统,因此很难继续。您应该查看

/usr/sbin/apache2ctl -S 

或者

/usr/sbin/httpd -S

这将显示你的 apache 所知道的虚拟主机,并将指示你是否启用了基于名称的虚拟主机,例如

 /usr/sbin/apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server test1.lan (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost test1.lan (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost centos1.lan (/etc/apache2/sites-enabled/000-default:94)
         port 80 namevhost host1.test.lan (/etc/apache2/sites-enabled/subhosts:41)
         port 80 namevhost host2.test.lan (/etc/apache2/sites-enabled/subhosts:49)
Syntax OK

如果你没有,*:80 is a NameVirtualHost那么你需要使用

NameVirtualHost *:80 

在您的 VirtualHost 定义之前的指令。

相关内容