Apache VHOST sort orderHow create make sure your VHOSTs are in the right order. |
I had this CentOS server; now I have a Fedora DRBD setup. And I mainly use Webmin to manage the settings. But creating virtual hosts is something different.
Tweet
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:
Include vhosts/*.conf
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
00awf-beeldendenklinkend.conf
00begeleider.conf
00bomeninfo.conf
00bszutphen.conf
00handidate.conf
00nicolekarrer.conf
00tradsys.conf
00voelkussen.conf
10snoezelen-pillow.conf
11snoezelen-kissen.conf
12coussin-calin.conf
19snoezelkussen.conf
20bobvosnet.conf
21ceesvosnet.conf
22daanvosnet.conf
23loesvosnet.conf
24marcvosnet.conf
29vosnet.conf
90sds82.conf
That’s it!