1 nginx服务端环境配置

#安装依赖
apt install -y build-essential libpcre3 libpcre3-dev zlib1g-dev  openssl libssl-dev
#下载nginx
wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -xzvf nginx-1.21.6.tar.gz 
mv nginx-1.21.6 nginx & cd nginx
#生成makefile
./configure --perfix=/root/work/c/nginx --with-debug
#clion同步文件使用
apt -y install rsync
apt -y install cmake
apt -y install gdb
apt -y install gdbserver

执行命令后,生成makefile
接下来我们配置clion新建项目,配置远程开发,配置好后同步代码,打开makefile配置索引,执行重新加载makefile项目 img.png img.png img.png img_1.png img_2.png 到这已经可以正常构建了,接下来我们安装gdb,gdbserver 任意打印日志

#在下述文件增加如下代码
#nginx/src/event/ngx_event.c->func ngx_process_events_and_timers
ngx_log_debug(NGX_LOG_DEBUG_EVENT,cycle->log,0,"hello world pg");

#配置文件修改
error_log  logs/error.log  debug;

点击clion build/install图标后执行

root@VM-4-11-debian:~/work/c/nginx/install# ./sbin/nginx 
root@VM-4-11-debian:~/work/c/nginx/install# ps -ef | grep nginx
root       19962       1  0 00:20 ?        00:00:00 nginx: master process ./sbin/nginx
nobody     19963   19962  0 00:20 ?        00:00:00 nginx: worker process
root       20126   15975  0 00:21 pts/1    00:00:00 grep --color=auto nginx
root@VM-4-11-debian:~/work/c/nginx/install# gdbserver --attach :9999 19963
Attached; pid = 19963
Listening on port 9999
Remote debugging from host 101.34.177.36, port 45510
Detaching from process 19963

clion配置gdb,server如下,配置后clion正常调试,

img_3.png

#日志正常输出
root@VM-4-11-debian:~# tail /root/work/c/nginx/install/logs/error.log 
2022/05/08 00:20:41 [debug] 19963#0: *1 free: 0000557D7CA3D600
2022/05/08 00:20:41 [debug] 19963#0: *1 free: 0000557D7CA4D620, unused: 152
2022/05/08 00:20:41 [debug] 19963#0: timer delta: 1
2022/05/08 00:20:41 [debug] 19963#0: worker cycle
2022/05/08 00:20:41 [debug] 19963#0: hello world pg