为什么此配置始终显示我的默认Web服务器?

时间:2019-04-21 11:47:13

标签: apache debugging web webserver virtualhost

我有附加的配置,我试图显示mysite.com(在最后定义为vhost),但它始终显示默认的索引页,即我在/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

1 个答案:

答案 0 :(得分:1)

您已在vm3.mysite.com块之外配置了VirtualHost,该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下的单独配置文件,该文件将自动包含在主配置中。这样一来,您就可以将虚拟主机设置与常规服务器配置区分开来,并避免以前的大多数混乱情况。

相关问题