In what order does Apache load conf files and which ones?

8

4

I'm looking at a CentOS 6.5 server with a webframework installed that has been added to over the years by many. There are what looks like 5 active .conf files in /conf, including httpd.conf.

In httpd.conf the include reads

Include conf.d/*.conf

and that grabs all the files in that directory, but without any specific order applied that I'm aware of, and so what about the /conf (no .d) directory?

Is there a setting that states the load order or are they just taken from a-z?

I'm not the server admin, I'm a developer and the problem lies in the paths for uploading files to a /Temp dir, where I have checked that the path specified is correct for the files I myself am concerned with.

So, the 1st question is:

Does Apache load everything from /conf or is there a list specified somewhere?

The 2nd question would be:

In what order does Apache load the files, alphabetically?

Lastly:

Does a file that does not end in .conf get included? For example if I name something myconfig.conf.old will Apache skip it?

chrtp

Posted 2014-01-22T11:56:53.580

Reputation: 83

Answers

13

The order is alphabetical. It only loads what the Include path specifies. In the case of Include conf.d/*.conf apache will load all files with names ending in .conf.

This is an extract from Apache Documentation :

Shell-style (fnmatch()) wildcard characters can be used to include several files at once, in alphabetical order. In addition, if Include points to a directory, rather than a file, Apache will read all files in that directory and any subdirectory. But including entire directories is not recommended, because it is easy to accidentally leave temporary files in a directory that can cause httpd to fail.

suspectus

Posted 2014-01-22T11:56:53.580

Reputation: 3 957

1@chrtp, and why a file starting with t would override all else? – Andrew Savinykh – 2017-02-13T13:17:52.527

Thank you, that answers questions 1 & 2 certainly. I looked though the Apache docs but couldn't find the answer. – chrtp – 2014-01-22T13:22:14.490

Broadly (order of config items overrides earlier items) that is correct. Certainly if the commands are in the same configuration section. But for example it is possible (using AllowOverride) to override config items with config in an .htaccess file. – suspectus – 2014-01-22T13:31:59.063

Sorry, I edited my comment before I saw yours. There is no .htaccess in this case, but there is a file starting with 't' that is overriding all else. I'm going to rename or move the file. – chrtp – 2014-01-22T13:35:13.680

1

I you want to change the order just open the first conf file in directory sites-available and before first VirtualHost *:80 add your virtual host code.

In my case I want hub.xxx.com.conf to be before bayxxx.com.conf. So I open hub.xxx.com.conf and place virtual host at the beginning of a file

For example:

<VirtualHost *:80>
    DocumentRoot /www/hub.xxx.com/www/root
    ServerName hub.xxx.com
    ServerAlias *.hub.xxx.com
    <Directory "/www/hub.xxx.com/www/root">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /www/bayxxx.com/www/root
    ServerName bayxxx.com
    ServerAlias www.bayxxx.com
    <Directory "/www/bayxxx.com/www/root">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

Pavel

Posted 2014-01-22T11:56:53.580

Reputation: 111

1

Apache loads extra configuration based on the "Include" directive. It probably looks like this:

Include conf.d/*.conf

So, obviously, it includes everything in "conf.d" that looks like "*.conf".

To make it even more insane, you can add an arbitrary number of directories with "include" all of which could contain roughly the same config files, that all would happily override each other at start up...And then themselves be over-ridden by the .htaccess file in various hosted directories.

As near as I can tell, httpd.conf is first, followed by the directories in the order in which they are included and then alphabetically from there.

Good times. You can use apachectl -t or apachectl configtest to get some idea of whether or not your configuration is going to cause trouble.

Satanicpuppy

Posted 2014-01-22T11:56:53.580

Reputation: 6 169

1Thank you, it looks like someone has left a file called template.conf in there that of course loads last and then overrides any other files that specify the path to /Temp. I can only guess as to what else is being broken with that there! – chrtp – 2014-01-22T13:29:50.347

1@chrtp To add to the hilarity, directives can be specified at runtime using -C (for adding them before reading config files) and -c (for reading them after config files), so you could source an entire different config from the command line on startup. – Satanicpuppy – 2014-01-22T13:47:44.453