为什么这个配置总是显示我的默认网络服务器?

Why does this config always shows my default web server?

我有附加的配置,我正在尝试显示 mysite.com(在最后定义为虚拟主机)但它总是显示默认索引页面,我在 /var/www/html/domains/default/index.php

我知道一个原因可能是我的 vhost 文件夹上的权限代码错误,但我认为现在不是这种情况,我没有在日志中看到常见的 forbidden 错误并用于调试目的我设置子目录的完整路径属于apache:apache

我也尝试将虚拟主机移到 .conf 的顶部,但没有任何区别。

ServerRoot "/etc/httpd"


Listen *:80
Listen *:443

Include conf.modules.d/*.conf


User apache
Group apache


ServerAdmin root@localhost


ServerName vm3.mysite.com:80

<Directory />
    AllowOverride all
    Require all granted
</Directory>



DocumentRoot "/var/www/html/domains/default"

<Directory "/var/www">
    AllowOverride All
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks


    AllowOverride All

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>


EnableSendfile on

IncludeOptional conf.d/*.conf


<VirtualHost mysite.com:80>
        DocumentRoot /var/www/html/domains/mysite.com
        ServerName mysite.com
        <Directory "/var/www/html/domains/mysite.com">
                allow from all
                Options None
                Require all granted
        </Directory>
</VirtualHost>


KeepAlive on

您在 VirtualHost 块之外配置了 vm3.mysite.com,apache 正在无条件使用并忽略 mysite.com 虚拟主机。您可以通过将 vm3.mysite.com 移动到单独的虚拟主机中来解决此问题(它们在配置文件中的位置并不重要,只要它们都在虚拟主机中即可)。

这是您的配置,为了清楚起见,对一些指令进行了重新组织,相关位移到了底部的适当 VirtualHost 块中:

ServerRoot "/etc/httpd"

Listen *:80
Listen *:443

User apache
Group apache

KeepAlive on
EnableSendfile on
Include conf.modules.d/*.conf
IncludeOptional conf.d/*.conf

<Directory "/var/www">
    AllowOverride All
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

<VirtualHost vm3.mysite.com:80>
    ServerAdmin root@localhost
    ServerName vm3.mysite.com
    DocumentRoot "/var/www/html/domains/default"
    <Directory />
        AllowOverride all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost mysite.com:80>
    DocumentRoot /var/www/html/domains/mysite.com
    ServerName mysite.com
    <Directory "/var/www/html/domains/mysite.com">
        allow from all
        Options None
        Require all granted
    </Directory>
</VirtualHost>

为了让事情更有条理,您可以考虑将这些虚拟主机移动到 conf.d/<your_file>.conf 下的单独配置文件中,该文件将自动包含在主配置中。这将允许您将 vhost 设置与一般服务器配置分开,并避免以前的大部分混淆。