Apache VHOST sort orderHow create make sure your VHOSTs are in the right order.
I have this CentOS server. And I mainly use Webmin to manage the settings. But creating virtual hosts is something different. Webmin lists your virtual hosts in alphabetical order - and this is never the order in which the virtual hosts are stored in /etc/httpd/conf/httpd.conf, if you choose to do so.
The virtual hosts are stored in order of entry. That is a bit of a pain and it’s a pity the Webmin interface does not work in the same way as the Webmin interface for the firewall rules; there one has these arrows on the right to move a rule up- or downwards in the list. Would be a cool thing to implement in the virtual host list too.
Anyway, Webmin does a good job if you store the virtual hosts in separate files - if you make modifications to a virtual host, it save the changes in the correct file.
To manage your hosts like this and move them from the httpd.conf file into separate files, first create a folder /etc/httpd/vhosts and then create files for each vhost listed in http.conf. Copy/Paste each complete <VirtualHost></VirtualHost> block. When you are done, remove all virtual hosts from http.conf and add the following line of text:
Save and exit http.conf
You can now control the load order of the virtual hosts easily by beginning the file names with a number. Number the catch-all host the highest. Then check if you did a good job:
$ apachectl configtest
If all is OK, restart Apache:
$ apachectl graceful
Or, if you did it all via Webmin, click Apply changes at the top-right of the window of the Apache Webserver interface.
Another thing what I miss from Webmin’s virtual host overview is the name of the file where the virtual host is in. But you can see it if you click a virtual host’s name and then click 'Edit Directives':
My list of vhosts looks like this:
$ ls -C1 /etc/httpd/vhosts