PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

[FIXED] Why does this config always shows my default web server?

 September 21, 2022     apache, debugging, virtualhost, web, webserver     No comments   

Issue

I have the attached config, I am trying to display mysite.com (defined as vhost at the very end) but it always shows the default index page, the one I have in /var/www/html/domains/default/index.php

I know one cause can be wrong permission code on my vhost folder, but I don't think that is the case now, I don't see that common forbidden error in logs and for debugging purposes I set the full path of sub-directories to belong to apache:apache

I also tried to move my vhost at the top of the .conf but it made no difference.

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

Solution

You have vm3.mysite.com configured outside of a VirtualHost block, which apache is using unconditionally and ignoring the mysite.com vhost. You could fix this by moving vm3.mysite.com into a separate vhost (where they occur in the config file doesn't really matter, so long as they're both in a vhost).

Here is your config, with some of the directives reorganized for clarity, and the relevant bits moved into a proper VirtualHost block at the bottom:

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>

To keep things better organized, you might consider moving those vhosts to a separate config file under conf.d/<your_file>.conf which will be included in the main config automatically. This would allow you to keep your vhost settings separate from the general server config and avoid most of the previous confusion.



Answered By - AfroThundr
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing