<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Red Leopard &#187; httpd</title>
	<atom:link href="http://www.redleopard.com/tag/httpd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redleopard.com</link>
	<description>A Stranger in a Strange Land</description>
	<lastBuildDate>Tue, 20 Dec 2011 14:55:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Apache Directory Indexing</title>
		<link>http://www.redleopard.com/2009/12/apache-directory-indexing/</link>
		<comments>http://www.redleopard.com/2009/12/apache-directory-indexing/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 22:47:59 +0000</pubDate>
		<dc:creator>kelly</dc:creator>
				<category><![CDATA[KellyBlog]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.redleopard.com/?p=812</guid>
		<description><![CDATA[Sometimes a problem persists long enough—is an irritant long enough—that I&#8217;ll burn an entire Sunday morning simply out of spite. Today&#8217;s irrational time-waste went to solving &#8220;Directory index forbidden by Options directive.&#8221; [marmaduke ~] $ cat /var/log/httpd/error_log \ &#124; grep '\[error\]' \ &#124; head -1 [Sun Dec 06 09:25:05 2009] [error] [client 192.168.2.29]↩ Directory index [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes a problem persists long enough—is an irritant long enough—that I&#8217;ll burn an entire Sunday morning simply out of spite. Today&#8217;s irrational time-waste went to solving &#8220;Directory index forbidden by Options directive.&#8221;</p>
<div class="terminal">
<pre>
[marmaduke ~] $ <span style="color: green;">cat /var/log/httpd/error_log \
 | grep '\[error\]' \
 | head -1</span>
[Sun Dec 06 09:25:05 2009] [error] [client 192.168.2.29]↩
Directory index forbidden by Options directive:↩
/var/www/documentation/public_html/
</pre>
</div>
<p>I have a development server that I use to offload work from my laptop.</p>
<div class="terminal">
<pre>
[marmaduke ~] $ <span style="color: green;">hostname</span>
marmaduke

[marmaduke ~] $ <span style="color: green;">cat /etc/redhat-release</span>
CentOS release 5.4 (Final)
</pre>
</div>
<p>Among other things, marmaduke hosts scads of apache virtual hosts, including documentation. I&#8217;ve wanted to index the documentation directory for quite sometime but never could get apache configured to auto index.</p>
<p>Every configuration problem has already been solved by someone else. A quick search (<a href="http://www.google.com/search?hl=en&#038;as_q=apache+allow+directory+index">apache+allow+directory+index</a>) yielded surprisingly consistent instructions.</p>
<p>These instructions yielded consistent failure for me. I simply could not get auto indexing to work. Until now.</p>
<p>My apache installation is a basic yum install.</p>
<div class="terminal">
<pre>
[marmaduke ~] $ <span style="color: green;">yum list | grep httpd | grep installed</span>
httpd.x86_64           2.2.3-31.el5.centos    installed
httpd-devel.x86_64     2.2.3-31.el5.centos    installed
httpd-manual.x86_64    2.2.3-31.el5.centos    installed
</pre>
</div>
<p>I&#8217;ve extracted (below) a partial listing of relevant parts from the httpd.conf file.</p>
<p>I include configuration files from two directories: module configurations in /etc/httpd/conf.d/ and all virtual host configurations in /etc/httd/conf.d/hosts/.</p>
<p>For the most part, I leave httpd.conf untouched. Note that apache runs under the user and group named &#8216;apache&#8217;.</p>
<div class="terminal">
<pre>
<span style="color: gray;"># /etc/httpd/conf/httpd.conf (partial listing)</span>
Listen 80

Include conf.d/*.conf
Include conf.d/hosts/*.conf

User apache
Group apache

ServerName marmaduke:80
UseCanonicalName Off

DocumentRoot "/var/www/html"

&lt;Directory /&gt;
    Options FollowSymLinks
    AllowOverride None
&lt;/Directory&gt;

&lt;Directory "/var/www/html"&gt;
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
&lt;/Directory&gt;

DirectoryIndex index.html index.html.var

IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

NameVirtualHost *:80
</pre>
</div>
<p>Permissions are important.</p>
<p>I place my documentation directories in /var/www/documentation/public_html and the entire tree from /var/www/documentation downwards has the same user and group name. All directories have 755 permission and all non-directories have 644 permission.</p>
<div class="terminal">
<pre>
[marmaduke ~] $ <span style="color: green;">ll /var/www</span>
drwxr-xr-x 3 kelly apache 4096 Dec  6 09:23 documentation

[marmaduke ~] $ <span style="color: green;">ll /var/www/documentation</span>
drwxr-xr-x 7 kelly apache 4096 Dec  6 11:51 public_html

[marmaduke ~] $ <span style="color: green;">ll /var/www/documentation/public_html</span>
-rw-r--r-- 1 kelly apache 5174 Dec  6 09:33 favicon.ico
drwxr-xr-x 2 kelly apache 4096 Dec  6 09:21 icecast-2.3.2
drwxr-xr-x 3 kelly apache 4096 Dec  6 12:00 mysql-5.0
drwxr-xr-x 4 kelly apache 4096 Dec  6 11:50 mysql-5.1
drwxr-xr-x 3 kelly apache 4096 Dec  6 11:51 mysql-5.4
drwxr-xr-x 3 kelly apache 4096 Dec  6 11:51 mysql-5.5

[marmaduke ~] $ <span style="color: green;">ll /var/www/documentation/public_html/mysql-5.0</span>
drwxr-xr-x 3 kelly apache 4096 Dec  6 10:05 en
</pre>
</div>
<p>My virtual host enables indexing through the Directory directive. So far, this is consistent with most of the instructions found through web search. Yet, auto indexing still didn&#8217;t work for me.</p>
<div class="terminal">
<pre>
<span style="color: gray;"># /etc/httpd/conf.d/hosts/documentation.conf</span>
&lt;VirtualHost *:80&gt;
  DocumentRoot /var/www/documentation/public_html
  ServerName documentation.site
  Options Indexes FollowSymLinks

  &lt;Directory "/var/www/documentation/public_html"&gt;
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all
  &lt;/Directory&gt;

  RewriteEngine on
  RewriteLogLevel 1
&lt;/VirtualHost&gt;
</pre>
</div>
<p>It turns out that there is a nastly little surprise in one of the configuration files that comes standard with the centos yum install. </p>
<p>Inside LocationMatch, there the Options directive turns off Indexes. From the apache documentation, &#8220;<b>Regardless of any access restrictions placed in &lt;Directory&gt; sections, the &lt;Location&gt; section will be evaluated last…</b>&#8221;</p>
<div class="terminal">
<pre>
<span style="color: gray;"># /etc/httpd/conf.d/welcome.conf</span>
&lt;LocationMatch "^/+$"&gt;

  # this is the culprit!
  <b>Options -Indexes</b>

  ErrorDocument 403 /error/noindex.html
&lt;/LocationMatch&gt;
</pre>
</div>
<p>Since <code>LocationMatch</code> is evaluated last, the <code>-Indexes</code> parameter disables options set in any <code>Directory</code> directive. Either changing the parameter <code>-Indexes</code> to <code>Indexes</code> or deleting the welcome.conf file will allow auto indexing (assuming the other configurations are correct).</p>
<p><img width="592" height="445" alt="screenshot of apache directory listing" src="/images/apache-directory-index.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redleopard.com/2009/12/apache-directory-indexing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

