[英]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
我可以看到这个模块已经启用了
我还在mods-available文件夹中插入了helloworld.conf
<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”,但设置了“helloworld_handler”和SetHandler。 您需要更改为“SetHandler helloworld”才能使模块不衰落。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.