Apache 2.4 + PHP-FPM,捕获错误页面 [英] Apache 2.4 + PHP-FPM, catching 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>
我正在尝试捕获对不存在的* .php文件的所有请求.
I'm trying to catch all requests for non-existing *.php files.
例如,如果/var/www/awesome/index.php
存在并且我转到 http://foo.com/index.php 我得到正确的响应,但是如果/var/www/awesome/foo.php
不存在,我将转到 http://foo. com/foo.php ,我只是得到File not found.
的响应.
For example, if /var/www/awesome/index.php
exists and I go to http://foo.com/index.php I get the correct response, but if /var/www/awesome/foo.php
does not exist and I go to http://foo.com/foo.php, I am simply getting a response of File not found.
.
未读取.htaccess
文件,因为Apache将所有内容交给了PHP-FPM.
The .htaccess
file isn't being read because Apache hands everything off to PHP-FPM.
我需要捕获所有404请求并显示一个常见的错误页面,就像您通常在任何网站上看到的那样.
I need to catch all 404 requests and show a common error page, as you would normally see on any site.
但是,由于Apache将所有内容交给了php-fpm,因此似乎无法正确处理这些错误.
However, since Apache hands everything off to php-fpm, it doesn't seem to be handling these errors properly.
推荐答案
我曾经遇到过同样的问题,最后我解决了它.
I used to have the same problem and finally I fixed it.
尝试在ProxyPassMatch设置之后添加此内容:
Try add this after ProxyPassMatch setting:
ProxyErrorOverride on
顺便说一句,不要忘记你的
BTW, do not forget your
ErrorDocument 404 /path/to/file
设置.
这篇关于Apache 2.4 + PHP-FPM,捕获错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!