Pet*_*ton 6 apache error-handling .htaccess
在我的网站上,我希望它将所有错误500错误重定向到/500.html.截至目前,一些页面显示GET
http://localhost/ [HTTP/1.0 500 Internal Server Error 1ms]在Developer Tools中.我试过通过编辑实现这个/etc/apache2/sites-enabled/000-default.conf.该文件如下所示:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ErrorDocument 500 /500.html
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Run Code Online (Sandbox Code Playgroud)
我也尝试过编辑apache2.conf,.htaccess但我得到了相同的结果.
PS:我每次尝试重启Apache!
如果您尝试在 apache 中使用mod_phpwith SetHandler(一种非常常见的方式)拦截来自 PHP 的 500 个错误,那么答案是您不能。据我所知,这不是受支持的功能。
但是,有一些方法可以通过它的 FastCGI 接口 ( PHP-FPM ) 和 Apache代理模块使用 PHP来实现您的需求。
首先,您可能需要确保mod_proxy和proxy_fcgi_module安装在您的服务器上并在 Apache 配置中启用,如下所示:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Run Code Online (Sandbox Code Playgroud)
还要确保 PHP-FPM 作为服务安装并运行,它使用的默认端口是 9000。
然后用以下内容替换您的 apache PHP 配置(可能在 /etc/httpd/conf.d/php.conf 中)。
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
DirectoryIndex /index.php index.php
Run Code Online (Sandbox Code Playgroud)
这意味着您现在正在使用 Apache 代理模块向 PHP 发送流量。可以指示 Apache 拦截来自代理模块的错误响应,并在您的VirtualHost部分中使用以下自定义错误处理程序。
ProxyErrorOverride On
ErrorDocument 500 /500.html
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1439 次 |
| 最近记录: |