在 ubuntu 16.04 上配置 apache 模块
configure apache module on ubuntu 16.04
我在 ubuntu 16.04
上创建了一个 hello world 模块
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int helloworld_handler(request_rec* r)
{
if (!r->handler || strcmp(r->handler, "helloworld"))
return DECLINED;
if (r->method_number != M_GET)
return HTTP_METHOD_NOT_ALLOWED;
ap_set_content_type(r, "text/html");
ap_rprintf(r, "Hello, world!");
return OK;
}
static void register_hooks(apr_pool_t* pool)
{
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
用这个命令编译它:
apxs -iac mod_helloworld.c
我可以看到模块正在启动它
apache2ctl -M
和
a2enmod
如果我运行
sudo a2enmod helloworld
我可以看到这个模块已经启用
我也把这个 helloworld.conf 插入文件夹 mods-available
<Location /helloworld>
SetHandler helloworld_handler
</Location>
并且文件 helloworld.load 包含
LoadModule helloworld_module /usr/lib/apache2/modules/mod_helloworld.so
我应该如何配置它才能在浏览器中看到调用输出
mod_helloworld.so在/usr/lib/apache2/modules
之下
如果我root@ubuntu:/var/log/apache2# tail -f access.log
我明白了
127.0.0.1 - - [03/Aug/2017:03:18:14 -0700] "GET /helloworld HTTP/1.1" 404 500 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"
如何解决?
您在 C 代码中检查 "helloworld",但使用 SetHandler 设置 "helloworld_handler"。您需要更改为 "SetHandler helloworld" 才能让您的模块不 DECLINE。
我在 ubuntu 16.04
上创建了一个 hello world 模块#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int helloworld_handler(request_rec* r)
{
if (!r->handler || strcmp(r->handler, "helloworld"))
return DECLINED;
if (r->method_number != M_GET)
return HTTP_METHOD_NOT_ALLOWED;
ap_set_content_type(r, "text/html");
ap_rprintf(r, "Hello, world!");
return OK;
}
static void register_hooks(apr_pool_t* pool)
{
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
用这个命令编译它:
apxs -iac mod_helloworld.c
我可以看到模块正在启动它
apache2ctl -M
和
a2enmod
如果我运行
sudo a2enmod helloworld
我可以看到这个模块已经启用
我也把这个 helloworld.conf 插入文件夹 mods-available
<Location /helloworld>
SetHandler helloworld_handler
</Location>
并且文件 helloworld.load 包含
LoadModule helloworld_module /usr/lib/apache2/modules/mod_helloworld.so
我应该如何配置它才能在浏览器中看到调用输出
mod_helloworld.so在/usr/lib/apache2/modules
之下如果我root@ubuntu:/var/log/apache2# tail -f access.log
我明白了
127.0.0.1 - - [03/Aug/2017:03:18:14 -0700] "GET /helloworld HTTP/1.1" 404 500 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"
如何解决?
您在 C 代码中检查 "helloworld",但使用 SetHandler 设置 "helloworld_handler"。您需要更改为 "SetHandler helloworld" 才能让您的模块不 DECLINE。