Apache虚拟主机未正常工作

8
一些虚拟主机文件出现了问题,我无法确定原因——可能是我的大脑还没有完全清醒。目前,我通过符号链接将/etc/apache2/目录下的sites available中的两个站点启用了。
0 Nov 21 12:24 000-default -> ../sites-available/default
0 Nov 21 14:52 001-site -> ../sites-available/site

我的虚拟主机文件如下:

默认

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName (the IP Address from my Server)
        ServerAlias (the 2nd IP Address from my Server)
        DocumentRoot /var/www/default
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/default>
                Options FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

站点

<VirtualHost *:80>
    ServerAdmin myname@example.de
    DocumentRoot /var/www/site/
    ServerName jobbörse-köln.de
    ServerAlias www.example.de ww.example.de w.example.de

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/site>
            Options FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/site-error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/site-access.log combined
</VirtualHost>

不知怎么的,当我访问"example.de"时,我进入了默认目录而不是站点目录。 甚至日志文件也是如此:

site-error.log
site-access.log

停留在0字节......我做错了什么?我敢打赌这是一些愚蠢而简单的东西......


你的vhost.conf文件在哪里?当你访问你的网站时,你看到了什么?你的httpd.conf呢? - Keerthivasan
我的Vhost文件位于: /etc/apache2/sites-available 并且它们会链接到 /etc/apache2/sites-enabled 我的apache2.conf位于 /etc/apache2/当我访问www.example.de时,我从 /var/www/default/ 而不是 /var/www/site/获取index.php - Kris
1个回答

9

您在虚拟主机条目中同时使用了默认的80端口。因此,我希望您在配置中使用NameVirtualHost *:80。

在您分享的配置中,虚拟主机在80端口上重叠,因此第一个具有优先权。


我无法在端口80上的VHost上继续监听了吗? - Kris
2
@y_nk 我猜想您在使用与上述相同的IP+PORT组合时遇到了问题,例如(:80),其中代表所有IP(对于确定的IP,如209.207.228.12:80,可能会有所不同)。如果是这样,那么您需要告诉Apache *:80被两个不同的VirtualHost指令使用。因此,在添加这两个指令之前,您需要添加NameVirtualHost *:80(对于上述情况)。然后,ServerAlias将相应地选择您的配置。希望这能解决您的问题。 - Mandip Mankotia
1
实际上,在 Stack Network 上挂了几个小时后,我找到了正确的答案:https://dev59.com/RGIk5IYBdhLWcg3wL7bj#19521307 看起来很奇怪,但它确实有效 :) 感谢 @MandipMankotia - y_nk
这个答案有些误导性。同时需要注意,NameVirtualHost指令已经被弃用多年了。 - Valerio Bozz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接