读书人

Nginx模块怎么调试

发布时间: 2012-07-04 19:33:54 作者: rapoo

Nginx模块如何调试
编写nginx.conf,将nginx设置为单进程调试模式

worker_processes  1;error_log  logs/error.log debug; #  记录调试日志 master_process  off;             #  单进程模式daemon          off;            pid /tmp/nginx_debug.pid;events {    worker_connections  1024;}http {    include       /etc/nginx/mime.types;    sendfile        on;    keepalive_timeout  65;    tcp_nodelay        on;    server {        listen   80;        server_name  localhost;        access_log  /tmp/access.log;        error_log  /tmp/error.log debug;        location /hello {            echo "helloworld";        }    }}

为了方便使用调试器, 可以单进程非daemon方式启动, 使用参数:
daemon off;master_process off;



编写模块ngx_module_echo
在ngx_module_echo
回到nginx的源码目录进行安装:
~/nginx-0.8.9/#./configure --add-module=/home/doyoueat/ngx_module_echo/ --with-debugmakesudo make install

然后运行一下看看,先测一下配置文件的正确性:
~/nginx-0.8.9/#./objs/nginx -c /home/doyoueat/ngx_module_echo/nginx.conf -tthe configuration file /home/doyoueat/ngx_module_echo/nginx.conf syntax is okconfiguration file /home/doyoueat/ngx_module_echo/nginx.conf test is successful

运行之:
~/nginx-0.8.9/#./objs/nginx -c /home/renlu/ngx_module_echo/nginx.conf

在另一个终端执行一个curl:
~#curl http://127.0.0.1/hellohelloworld

读书人网 >开源软件

热点推荐