Apache忽略自定义模块

时间:2017-07-19 16:03:04

标签: apache apache-modules

所以我正在尝试创建自己的apache模块。现在我试图让它返回403只是为了测试它,但似乎apache完全忽略了模块并返回默认页面。以下是我的代码的相关部分:

x[0]=1

我的apache配置文件如下所示:

static int request_hook(request_rec* r){
  return HTTP_FORBIDDEN;
}

/* ********************************************
    Register module to Apache
   ******************************************** */

static void register_hooks(apr_pool_t *p)
{
    // We want to hook first so we can issue a deny ASAP if needed
    ap_hook_log_transaction( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);
}

module AP_MODULE_DECLARE_DATA my_module = {
    STANDARD20_MODULE_STUFF,
    NULL,              /* dir config creater */
    NULL,                       /* dir merger --- default is to override */
    NULL,                       /* server config */
    NULL,                       /* merge server configs */
    NULL,                   /* command apr_table_t */
    register_hooks              /* register hooks */
};

通过执行

编译
<VirtualHost *:80>
        DocumentRoot /var/www/html
        SetHandler      my_module
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

固定。问题是功能:

ap_hook_log_transaction( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);

应该是:

ap_hook_handler( request_hook, NULL, NULL, APR_HOOK_REALLY_FIRST);