Nginx模块如何调试

编写nginx.conf,将nginx设置为单进程调试模式 
代码   收藏代码
  1. worker_processes  1;  
  2.   
  3. error_log  logs/error.log debug; #  记录调试日志   
  4. master_process  off;             #  单进程模式  
  5. daemon          off;              
  6.   
  7. pid /tmp/nginx_debug.pid;  
  8. events {  
  9.     worker_connections  1024;  
  10. }  
  11. http {  
  12.     include       /etc/nginx/mime.types;  
  13.     sendfile        on;  
  14.     keepalive_timeout  65;  
  15.     tcp_nodelay        on;  
  16.     server {  
  17.         listen   80;  
  18.         server_name  localhost;  
  19.         access_log  /tmp/access.log;  
  20.         error_log  /tmp/error.log debug;  
  21.         location /hello {  
  22.             echo "helloworld";  
  23.         }  
  24.     }  
  25. }  

为了方便使用调试器, 可以单进程非daemon方式启动, 使用参数: 
代码   收藏代码
  1. daemon off;  
  2. master_process off;  



编写模块ngx_module_echo 
在ngx_module_echo 
回到nginx的源码目录进行安装: 
代码   收藏代码
  1. ~/nginx-0.8.9/#./configure --add-module=/home/doyoueat/ngx_module_echo/ --with-debug  
  2. make  
  3. sudo make install  

然后运行一下看看,先测一下配置文件的正确性: 
代码   收藏代码
  1. ~/nginx-0.8.9/#./objs/nginx -c /home/doyoueat/ngx_module_echo/nginx.conf -t  
  2. the configuration file /home/doyoueat/ngx_module_echo/nginx.conf syntax is ok  
  3. configuration file /home/doyoueat/ngx_module_echo/nginx.conf test is successful  

运行之: 
代码   收藏代码
  1. ~/nginx-0.8.9/#./objs/nginx -c /home/renlu/ngx_module_echo/nginx.conf  

在另一个终端执行一个curl: 
代码   收藏代码
  1. ~#curl http://127.0.0.1/hello  
  2. helloworld  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值