I spent the majority of this week debugging some Apache ModRewrite rules. (Yes, today is Wednesday.) It shouldn’t have taken so long. The rules themselves weren’t complex, but the server environment is.
Our production web site consists of a load balancer, Memcached server, two synchronized app servers, and two synchronized static file servers. There are obsolete, broken, and duplicate Apache config files distributed in various directories across the app and static servers. Many of the config files recursively included directories full of other config files. By trial-and-error, I sifted through them all, adding debug statements and restarting httpd, over and over and over. Nothing worked; Apache ignored every file I touched.
As usual, it turns out there’s an easier way to discover exactly which .conf files Apache is using.
First, get some data about your running Apache process:
$ ps ax | grep httpd 21765 ? Ss 0:00 /usr/sbin/httpd -f /var/www/conf/example.com.conf -E /var/www/logs/example.com-20140514-startup.log
This is valuable information, because now that we know the exact binary and config file Apache is running with, we can use the -S option to show VirtualHost settings:
$ /usr/sbin/httpd -f /var/www/conf/example.com.conf -S VirtualHost configuration: *:80 is a NameVirtualHost default server www.example.com (/var/www/conf/virtual/example.com/www.example.com.conf:1) port 80 namevhost www.example.com (/var/www/conf/virtual/example.com/www.example.com.conf:1) port 80 namevhost www2.example.com (/var/www/conf/virtual/example.com/www2.example.com.conf:1) ...
From the output above, we see that
www.example.coms VirtualHost is defined in
That’s all there is to it — no guesswork necessary.