Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running a standard installation of Apache 2.4.6 (Amazon) with PHP 5.4.21 using the following configuration for my virtual host:

DirectoryIndex index.php
# ...
FallbackResource /index.php

My index.php is the epitome of simple:

<?php echo "Hello world";

Accessing http://<server-name>/ mysteriously shows the full page only after five seconds! Any other page has the expected response time (which is fast).

Those five seconds, as I came to find out, are related to the default waiting time of the Keep-Alive feature; in this case, the last few bytes of the chunked response are not sent until Apache severs the connection after that waiting time. Btw, that also completely ruins any gains that a persistent connection would otherwise give you.

Is this a known bug of Apache or am I missing something extremely obvious here?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

From this bug report I realised that this problem could be related to the DirectoryIndex directive.

The standard Apache installation comes with the following section in the configuration:

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

Any directives following this statement, such as the one in your virtual host, will not overwrite this setting; rather, it gets added to a stack of pages that will be attempted when the index is requested. This behaviour can be confirmed when you perform strace httpd -X and check the stat() calls right after the request has been read, e.g.:

stat("/path/to/vhost/index.html", 0x7fff9dc41b90) = -1 ENOENT
stat("/path/to/vhost/index.php", {st_mode=S_IFREG|0664, st_size=130, ...}) = 0

Although I can't tell exactly why, any previous DirectoryIndex directive must be cleared before specifying DirectoryIndex index.php, i.e. index.php MUST be the first page that's attempted to handle the request.

This can be done using the following configuration:

DirectoryIndex disabled
DirectoryIndex index.php
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.