nginx调试方法

114 篇文章 1 订阅
16 篇文章 0 订阅

2015-05-02 wcdj


摘要:调试 nginx用到的工具有: secureCRT, curl, wget, gdb, cgdb, strace, pstack, addr2line等。

首先是下载源码,可以通过curl或wget来完成。
curl -O http://nginx.org/download/nginx-1.2.0.tar.gz
wget http://nginx.org/download/nginx-1.2.0.tar.gz

编译带调试和禁止优化的nginx,编译后可以通过./nginx -V命令查看
./configure --prefix='/data/home/gerryyang/LAMP/nginx/install/nginx-1.2.0' --with-debug --without-http_rewrite_module --with-cc-opt='-ggdb3 -O0'
为了查看nginx中定义的宏,需要使用-ggdb3选项
使用-g和-ggdb3编译后的大小区别
~/LAMP/nginx/install/nginx-1.2.0/sbin$ls -rtlh
total 18M
-rwxrwxr-x 1 gerryyang gerryyang 2.6M May 2 18:08 nginx.old
-rwxrwxr-x 1 gerryyang gerryyang 15M May 2 19:06 nginx

通过刷新所有源文件的时间戳,间接达到重新编译出一个新的nginx,这样做可以修改configure生成的Makefile文件
find . -name "*.c" | xargs touch

修改nginx配置,设置nginx只启动一个worker进程
worker_processes 1;

调试nginx启动和后续过程,最简单的方法是,将master进程和worker进程逻辑全部合在一个进程里,修改nginx配置
daemon off;
master_process off;
fork场景的调试方法,让gdb跟踪fork之后的子进程
set follow-fork-mode child

先使用curl测试nginx是否可以正常服务
curl -v "http://10.206.131.144:9001/"
* About to connect() to 10.206.131.144 port 9001 (#0)
*   Trying 10.206.131.144... connected
* Connected to 10.206.131.144 (10.206.131.144) port 9001 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: 10.206.131.144:9001
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.2.0
< Date: Sat, 02 May 2015 10:21:54 GMT
< Content-Type: text/html
< Content-Length: 151
< Last-Modified: Sat, 02 May 2015 09:19:03 GMT
< Connection: keep-alive
< Accept-Ranges: bytes
< 
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
* Connection #0 to host 10.206.131.144 left intact
* Closing connection #0


使用gdb调试nginx启动的方法
~/LAMP/nginx/install/nginx-1.2.0/sbin$gdb --args ./nginx -c conf/nginx.conf
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /data/home/gerryyang/LAMP/nginx/install/nginx-1.2.0/sbin/nginx...done.
(gdb) r
Starting program: /data/home/gerryyang/LAMP/nginx/install/nginx-1.2.0/sbin/nginx -c conf/nginx.conf
[Thread debugging using libthread_db enabled]


使用strace调试的方法
strace -s1024 -p30946
Process 30946 attached - interrupt to quit
epoll_wait(3, 

Refer

[1] http://daniel.haxx.se/docs/curl-vs-wget.html



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值