简体   繁体   English

apache配置文件中的自定义错误(不是错误页面)

[英]Custom errors in apache config files (not error pages)

I'm not looking to create custom error pages, but to actually issue error messages when the config file is parsed. 我不是要创建自定义错误页面,而是在解析配置文件时实际发出错误消息。 Specifically, I want to use an <IfModule> to throw up an error if the module hasn't been loaded, so it's easier to debug. 具体来说,如果模块尚未加载,我想使用<IfModule>来抛出错误,因此调试起来更容易。

For Httpd 2.4 see http://httpd.apache.org/docs/2.4/en/mod/core.html#error 对于Httpd 2.4,请参阅http://httpd.apache.org/docs/2.4/en/mod/core.html#error

For older versions 适用于旧版本

<IfModule !mod_deflate.c>
     Mod_deflate_not_enabled.
</IfModule>

will raise something like 会提出类似的东西

Syntax error on line 7 of /etc/apache2/sites-enabled/000-default:
Invalid command 'Mod_deflate_not_enabled.', perhaps misspelled ...
   ...fail!

when you reload the server config. 当您重新加载服务器配置时。

This is the only kludgy thing I could think of (and requires mod_rewrite enabled): 这是我能想到的唯一的kludgy(并且需要启用mod_rewrite):

<IfModule !mod_deflate.c>
        ErrorDocument 500 "mod_deflate isn't available"
        RewriteEngine On
        RewriteRule .* - [R=500]
</IfModule>

If you find a better way to 'trigger' errors, I'm certainly interested ;) 如果您找到更好的方法来“触发”错误,我当然感兴趣;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM