# Have disabled apache site config file 000-default.conf, but it still seems active. Why?

I added a file mysite.conf to my apache sites-available folder with the correct settings, then enabled it and reloaded apache, and it isn't working. I want to disable the default site config as defined in 000-default.conf to see if that fixes the problem.

To achieve this I ran:

cd /etc/apache2/sites-available/
sudo a2dissite 000-default.conf


and everything appeared to work ok, however when I load mysite.com in my browser, I'm still seeing the default index.html file in /var/www/html/ (as indicated in 000-default.conf) even though I have enabled the site config file for my domain as follows:

<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias mysite.com

DocumentRoot /var/www/mysite.com

ErrorLog ${APACHE_LOG_DIR}/error_mysite.log CustomLog${APACHE_LOG_DIR}/error_access_mysite.log combined

</VirtualHost>


I have a file /var/www/mysite.com/index.php that I expect should have been loaded instead.

• Okay. Why are you messing with 000-default.conf?? What are you trying to do? Do you have one site to deploy or more than one? It is not advisable to mess-up your default site. It is at the very least a catch-all site used for security. What is it you really want to do???? – closetnoc Aug 2 '15 at 0:12
• @closetnoc One site currently, but would like to use subdomains or other domains to have more than one. I basically just want a different documentroot for each site. I thought it might be a requirement to disable the 000-default.conf to get my site working with the given documentroot, but from what you say probably not. – Highly Irregular Aug 2 '15 at 0:18
• You DO NOT want to disable 000-default.conf. How are you accessing the web server? Via a domain name? Or IP address or machine name. – closetnoc Aug 2 '15 at 0:20
• @closetnoc yes, via my mysite.com domain name, but it's loading /var/www/html/index.html rather than /var/www/mysite.com/index.php – Highly Irregular Aug 2 '15 at 0:21
• That is because there is no conf file for mysite.com in sites-available I am sure. The 000-default.conf site is a catch-all for any request the server does not have a configuration file for. If you have a domain name and it is resolving okay, the request should be for the domain name. If there is not configuration for that domain name, then it will use default which is what you want. It is a security measure. You will need to create a configuration file for your site. – closetnoc Aug 2 '15 at 0:24

Just as a matter of explanation for future users.

Your 000-default.conf file is a catch-all site and should be left alone. It is good for security. It can be frustrating when a site configuration does not work and the default site is served. I get it. Still, leave it alone. Many people are unaware of why the default site exists. Here is a bit of an explanation.

When Apache receives a request, it tries to match it to a configuration it knows about. So any request for example.com will look for a example.com.conf with a proper configuration. If there is no match, the 000-default.conf site is used. If a request for bogussite.com is seen and it does not exist on the server, then the 000-default.conf file is served. This is especially useful for IP address only requests. And we all hate those!! However, if there is an error in example.com.conf it is still possible that the 000-default.conf site is served making the exact reason why and how the configuration is failing a bit confusing and very frustrating.

I gave some sample configurations from a live server here: Virtualhost config: routing and wildcard usage

Push comes to shove, these should always work. You can cut and paste them exactly then make the necessary changes or modify your existing file(s). Your option. It is easy to go cross-eyed on this so be careful. We have all done it so you will not be alone.

@HighlyIrregular makes this point in his comments which should live.

You can always check the configuration in a shell session using...

$apachectl configtest  ... which should help troubleshoot issues. You will need to create your new/additional site(s) in your /etc/apache2/site-available/ directory using a file format similar to example.com.conf. You will also want to make sure that /etc/apache2/apache2.conf has Include sites-enabled/ or something similar as one of the last lines. When a change to any configuration file is made, Apache has to be restarted. Apache caches configurations in memory and changes will not be seen until it is restarted. On rare occasions, a restart does not work as expected. In this case, to rule this out as an issue, you will want to reboot your server. It is very possible that valid configurations are not seen when restarted. Not sure why. However, with a reboot, Apache is forced to re-cache the configuration files. It is like getting a bigger hammer. Well worth a try sometimes. • Thanks very much for your help! A reboot of the server fixed it in my case (when restarting apache didn't). It's also worth noting for other users that the command apachectl configtest is useful for detecting apache config errors (use it before reloading/restarting apache). – Highly Irregular Aug 2 '15 at 2:11 • I am glad things worked out. It was just a matter of using the right hammer!! – closetnoc Aug 2 '15 at 2:16 • @HighlyIrregular I added your suggestion to the answer... it was a good one that really should outlive any comment which can disappear in time. Thanks! I forget about this option and go commando most of the time. – closetnoc Aug 2 '15 at 2:27 • BTW- I just read your profile. I thought this could be of interest: careers.stackoverflow.com Just in case you didn't know... Cheers!! – closetnoc Aug 2 '15 at 4:38 • So what if I'm running my apache on a local server in the network, accessing it via IP, don't want to mess around with the 000-default.conf as you are advising, but still make it so that navigating a browser to the local server's IP will display one of the alternative virtual hosts (example.conf) instead of the default one? I think I'm looking for something like a DefaultVirtualHost = ... directive, but not sure it exists or how else to go about if. For now, I've put example.conf on port 8080, so tacking that onto the IP will get me to the page I want. Not a nice solution though. – domsson Jul 31 '17 at 14:38 I agree with user 'closetnoc' who replied at [2015-Aug-2 00:24:36Z] in response to the original post that wrote "The 000-default.conf site is a catch-all for any request the server does not have a configuration file for". And, I think we can make use of such 'catch-all site' as a last resort to safeguard and to enhance the overall security. The thing I tried to do is still allow the site '000-default.conf' to be activated, but make its configuration a little bit different that to constantly drop ALL requests WITHOUT sending response and then immediately CLOSE THE CONNECTION for all prohibited access, so that nothing is responded/revealed to the attempting requestor. Here is my '000-default.conf' file, for your reference: <VirtualHost *:80> # ServerName whatsoever ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog${APACHE_LOG_DIR}/default_error.log
CustomLog \${APACHE_LOG_DIR}/default_access.log combined

<Location />
<RequireAny>
# Example for 'Block all':
# Require ip 0.0.0.0/32
Require all denied

# Example for 'White list':
# Require ip 172.217.24.37/32
</RequireAny>
</Location>

SecRuleEngine On
SecRule RESPONSE_STATUS "403" "phase:4,id:1,drop"
</VirtualHost>


Be reminded to install the 'ModSecurity' module so that the directives 'SecRuleEngine' and 'SecRule' can be accepted. If you require additional assistance and reference on the topic of 'ModSecurity' module, suggest you search the Internet.

Hope the above helps!