Apache 2.4 + PHP-FPM, trap error pages

Here is my vhost file:

 <VirtualHost *:80>
   ServerName awesome.dev

   ## Vhost docroot
   DocumentRoot "/var/www/awesome"

   ## Directories, there should at least be a declaration for /var/www/awesome
   <Directory "/var/www/awesome">
     Options Indexes FollowSymLinks MultiViews
     DirectoryIndex index.php
     AllowOverride All
     Require all granted
   </Directory>

   ## Logging
   ErrorLog "/var/log/apache2/w0JhArMoDehc_error.log"
   ServerSignature Off
   CustomLog "/var/log/apache2/w0JhArMoDehc_access.log" combined

   ## Server aliases
   ServerAlias www.awesome.dev

   ## SetEnv/SetEnvIf for environment variables
   SetEnv APP_ENV dev

   ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/awesome/$1
 </VirtualHost>

      

I am trying to catch all requests for non-existent * .php files.

For example, if /var/www/awesome/index.php

exists and I go to http://foo.com/index.php I get the correct answer, but if /var/www/awesome/foo.php

not exist and I go to http://foo.com/foo.php I just get the answer File not found.

...

The file is .htaccess

not readable because Apache passes everything to PHP-FPM.

I need to catch all 404 requests and show the generic error page, as you usually see on any website.

However, since Apache is pushing everything to php-fpm, it seems to be handling these errors incorrectly.

+3


source to share


2 answers


I had the same problem and finally I fixed it.

Try adding this after the ProxyPassMatch parameter:

ProxyErrorOverride on

      



By the way, don't forget your

ErrorDocument 404 /path/to/file

      

Customization.

+2


source


As many problems can arise during the apache / php-fpm process, many errors can lead to a "File not found" response and in the logs "AH01071: Got error" Primary script unknown \ n '": (double slashes in paths, permissions, ...)

To track them down, you can:



  • Paste the apache configuration "LogLevel debug" and check the error log.
  • And / Or set the temporary config back to "simple apache just try", in my case it will lead me to permission issues (www 0751 should be 0755) an error that was previously invisible.

Ps: Take care of another thread, people say that using ProxyErrorOverride for this is a "really bad idea": https://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch

0


source







All Articles