Nginx模块如何调试

来源:互联网 发布:珠三角物流网络 编辑:程序博客网 时间:2024/06/07 19:05
编写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  
0 0