尝试修改nginx源码,第一步就是修改nginx,打印出hello world,顺便加下自己的名字。操作如下:
1: 去官网下载nginx源码
http://nginx.org/download/
2: 根据配置选项和系统情况生成makefile文件(这一步在修改完代码后是不用再执行的)
./configure --prefix=/usr/local/nginx
3: 根据makefile编译源码(修改代码后make会根据你修改的文件重新编译源码)
make
4: 安装源码
make install
5: 修改nginx探测配置的提示信息
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
根据输出搜索源代码:
cd nginx-1.8.0
grep 'syntax is ok' * -r
src/core/ngx_cycle.c: ngx_log_stderr(0, "nginx: the configuration file %s syntax is ok",
6: 修改源码并重新编译
vim src/core/ngx_cycle.c
ngx_log_stderr(0, "hello, Lisi make it\nnginx: the configuration file %s syntax is ok",
make && make install
7: 验证修改代码是否生效
/usr/local/nginx/sbin/nginx -t
nginx: hello, Lisi make it
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
高手都是阅读代码的一些核心功能进行改善,本人看不懂里面的代码是什么东东。
最后附上本人的网络课堂地址,如有兴趣请点击: 实践哥