1

I'm running an apache2 web server that came pre-installed on debian. Apache configuration hosts file is:

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/error.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerName sub1.domain.com
    ServerAlias www.sub1.domain.com
    DocumentRoot /var/www/sub1/public_html
    DirectoryIndex sub1.php

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/error.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerName sub2.domain.com
    ServerAlias www.sub2.domain.com
    DocumentRoot /var/www/sub2/public_html
    DirectoryIndex sub2.php

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

apachectl -S output:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server domain.com (/etc/apache2/sites-enabled/domain.com.conf:1)
         port 80 namevhost domain.com (/etc/apache2/sites-enabled/domain.com.conf:1)
                 alias www.domain.com
         port 80 namevhost sub1.domain.com (/etc/apache2/sites-enabled/domain.com.conf:10)
                 alias www.sub1.domain.com
         port 80 namevhost sub2.domain.com (/etc/apache2/sites-enabled/domain.com.conf:19)
                 alias www.sub2.domain.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

domain.com loads the default index.html file that came pre-installed at /var/www/html/index.html (Intended)

sub1.domain.com loads sub1.php. (Intended)

sub2.domain.com loads the default index file at /var/www/html/index.html. I can access the intended file, sub2.php, as a directory: sub2.domain.com/sub2.php

How can I make my second subdomain obey the DirectoryIndex directive, and load sub2.php my navigating to sub2.domain.com?

2
  • Apache itself only serves static content, so the question in the first place would be how you're intending to run PHP? It is not indicated in any way at your respective virtual hosts.
    – cora
    Sep 20, 2020 at 16:35
  • I have a PHP module for Apache installed. It is able to load PHP at sub1.domain.com and at sub2.domain.com/sub2. Even when I give it a dummy HTML file, it is loading the wrong file. Sep 20, 2020 at 20:02

1 Answer 1

0

I don't know what changed, but this morning (the day after posting this question) it is now loading the DirectoryIndex as intended.

This is probably a bug in Apache, specifically how it handles a changed DirectoryIndex when you reload. For posterity, I'm using systemd to reload the apache configuration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .