I set up a server which just went into production mode and we have realized that there's a problem with our mod_rewrite redirects if they try to re-route a PHP file that doesn't exist. The server's running apache 2.4.18 and PHP-FPM 7.0. It's the FPM part that I'm unaccustomed to. The apache guys on the Freenode IRC channel insisted that I should use the event MPM. One instructs apache to handle PHP files with this ProxyMatch directive within my VirtualHost directive:
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# THIS IS IT RIGHT HERE
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/var/www/html/
</VirtualHost>
The problem with this is that a request for some nonexistent file like http://example.com/path/to/file/that/does/not/exist.php will cause a 404 FILE NOT FOUND error before my mod_rewrite rules in an .htaccess file have a chance to redirect this request.
I found some helpful detail in the apache wiki but there's a warning about security at the bottom:
/uploads/malicious.jpg/lalalaalala.php
Would lead php-fpm to process that file (/uploads/malicious.jpg), and without certain sanity check, possibly lead to a compromised server.
Has anyone dealt with this issue in a way that is secure?