【问题标题】:Why does this config always shows my default web server?为什么这个配置总是显示我的默认 Web 服务器?
【发布时间】:2019-09-10 22:32:40
【问题描述】:

我有附加的配置,我正在尝试显示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

【问题讨论】:

    标签: apache debugging web webserver virtualhost


    【解决方案1】:

    您在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/&lt;your_file&gt;.conf 下的单独配置文件中,该文件将自动包含在主配置中。这将允许您将虚拟主机设置与常规服务器配置分开,并避免之前的大部分混淆。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多