0

我正在使用 apache 服务器版本 2.4

我已通过在配置期间指定 --prefix 将 apache 安装到自定义位置。

我在 mac os x 小牛队。

我正在使用用 c 编写的 apache 模块。我正在关注官方网站http://httpd.apache.org/docs/2.4/developer/modguide.html上的教程

我安装了 mod_example.c 下给出的模块:代码如下

/* Include the required headers from httpd */
#include "httpd.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"

/* Define prototypes of our functions in this module */
static void register_hooks(apr_pool_t *pool);
static int example_handler(request_rec *r);

/* Define our module as an entity and assign a function for registering hooks  */

module AP_MODULE_DECLARE_DATA   example_module =
{
    STANDARD20_MODULE_STUFF,
    NULL,            // Per-directory configuration handler
    NULL,            // Merge handler for per-directory configurations
    NULL,            // Per-server configuration handler
    NULL,            // Merge handler for per-server configurations
    NULL,            // Any directives we may have for httpd
    register_hooks   // Our hook registering function
};


/* register_hooks: Adds a hook to the httpd process */
static void register_hooks(apr_pool_t *pool) 
{

    /* Hook the request handler */
    ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
}

/* The handler function for our module.
 * This is where all the fun happens!
 */

static int example_handler(request_rec *r)
{
    /* First off, we need to check if this is a call for the "example" handler.
     * If it is, we accept it and do our things, it not, we simply return DECLINED,
     * and Apache will try somewhere else.
     */
    if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);

    // The first thing we will do is write a simple "Hello, world!" back to the client.
    ap_rputs("Hello, world!<br/>", r);
    return OK;
}

我添加了我的 Set Handler 如下

<IfModule example_module>
    <Location /*>
        SetHandler example_module
    </Location>
</IfModule>

当我尝试访问 localhost/ 时,我得到“它有效!” 屏幕。

但是当我尝试访问 localhost/asd 之类的 localhost 中的某些路径时,我收到以下错误

禁止的

您无权访问此服务器上的 /asd。服务器无法读取 htaccess 文件,拒绝访问是安全的

你能帮我解决这个问题吗?

4

0 回答 0