我在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"
如何解决这个问题?