3

We recently switched our Apache 2.4.7 mode from mpm_pre-fork to mpm_event. Since then we haven't been able to get our Files directive to work.

<Files "*.php">
  Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
</Files>

I did manage to get working with this convoluted mess:

<Files ~ "((^$)|(php))">

But, according to my regex knowledge, this will match files with "php" anywhere in the file name. I found the need to match the "null" case from this other question. We've also tried FilesMatch with the same result.

None of this makes any sense from what I can tell from the Apache 2.4 documentation. Has anyone else seen anything like this problem?

UPDATE: I rolled the server back to mpm_preforker and mod_php with no change. I then purged apache and php, re-installed as mpm_preforker and it worked again. I then upgraded to mpm_event and php-fpm and it stopped working after a bit. I'm trying to isolate where it breaks and will post what I find.

UPDATE2: This appears to be related to the fastcgi or php-fpm stuff. I have two <Files> directives, one for html and one for php that generate unique headers:

<Files *.html>
   Header always set X-Aaron-files "html match"
</Files>
<Files *.php>
   Header always set X-Aaron-files "php match"
</Files>

If I go to a fictitious php file, then I get a 404 message with the header for php-match. BUT if I go to a real php file, then the server executes the php file but does NOT return the headers indicating a php file match.

1

<Files "*.php"> works

Try another thing than a header, like a redirect page :

<Files "*.php">
redirect 301 / /anyPage.htm
</Files>

If you want to do the same with regexp you can do

<Files ~ "\.php">
redirect 301 / /anyPage.htm
</Files>

If you want to make the match to nothing & any php page:

<Files ~ "(^$|\.php)">
redirect 301 / /anyPage.htm
</Files>

Using filematch :

<FilesMatch "(^$|\.php)">
    redirect 301 / /anyPage.htm
</FilesMatch>

You can make the test it will works.

I suspect you got some intruction somewhere else which override your header

| improve this answer | |
  • Like I said, all we did was switch from mpm_prefork to mpm_event with php-fpm. How can we find if some instruction that overrides the items in the virtualHost tag? Most of our testing was to create custom headers, just to see if the directives were being processed correctly, that's how we found a pattern that finally worked. – Aaron Dec 21 '15 at 0:58
  • See updates in OP. – Aaron Jan 8 '16 at 1:07
0

This appears to be related to the fastcgi and php-fpm stuff.
Not sure how this made it through testing....

If the requested file is handled by php-fpm, then the directives are not processed.

If instead the file is not handled by php-fpm (which includes 404 responses for a missing php file), then the directives are processed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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