[dev][nginx] 在阅读nginx代码之前都需要准备什么
前言
以前,我读过nginx的源码,甚至还改过。但是,现在回想起来几乎回想不起任何东西,
只记得到处都是回调和异步,我的vim+ctags索引起来十分吃力。
几乎没有任何收获,都是因为当时打开代码就看,完全不了解背景和设计思想,只知其然不知其所以然。
如今,做好准备工作,再学习一下。
简单的时候,这个准备工作分两步:
1. 掌握一般性的http,https知识。(应该是都掌握的,不然也没有读nginx代码的理由)
2. 把这个页https://nginx.org/en/docs/ 从上到下读一遍。(我当然是跳着读的)
Author: classic_tong
详细如下:
一 获取代码
nginx官网提供的源码在这个位置:http://hg.nginx.org/nginx
github上有一个mirror: https://github.com/nginx/nginx
二 编译安装
两步,configure 然后make
[root@T9 nginx.git]# ls
auto conf contrib docs Makefile misc objs src
顶级目录是如上这样的,configure脚本在auto下面,但是必须在顶级目录运行。。如下这样:
./auto/configure --prefix=/root/OUTPUT_nginx/ \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gunzip_module \
--with-stream \
--with-stream_ssl_module \
--with-debug
然后,make,Make install,就装好了:
[root@T9 nginx.git]# ll /root/OUTPUT_nginx/
total
drwx------ nobody root Sep : client_body_temp
drwxr-xr-x root root Sep : conf
drwx------ nobody root Sep : fastcgi_temp
drwxr-xr-x root root Sep : html
drwxr-xr-x root root Sep : logs
drwx------ nobody root Sep : proxy_temp
drwxr-xr-x root root Sep : sbin
drwx------ nobody root Sep : scgi_temp
drwx------ nobody root Sep : uwsgi_temp
三 使用
(1)
直接运行二进制./sbin/nginx 会驱动nginx的daemon。一个master若干work进程:
[root@T9 OUTPUT_nginx]# ps -ef |grep nginx
root Sep09 ? :: nginx: master process ./nginx
nobody Sep09 ? :: nginx: worker process
使用,-s参数可以进行不同的daemon交互。例如 -s reload可以重新加载配置。
(2)最简配置
做了个最简配置,运行使用一下:
[root@T9 OUTPUT_nginx]# cat conf/nginx.conf
events {
}
http {
server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
}
[root@T9 OUTPUT_nginx]# tree /data/
/data/
├── images
│ └── .png
└── www
└── .html
在此基础上,通过以下文档,理解最基本的概念:
https://nginx.org/en/docs/beginners_guide.html
四 其他配置实验
通过文档完成其他场景的配置实验:
如何配置https server: https://nginx.org/en/docs/http/configuring_https_servers.html
如何配置Load Balance:https://nginx.org/en/docs/http/load_balancing.html
五 熟悉一般流程
nginx 处理一个请求的一般过程:https://nginx.org/en/docs/http/request_processing.html
nginx 处理一个stream的一般过程:https://nginx.org/en/docs/stream/stream_processing.html
六 nginx开发者指南
必须详细阅读,不可略过:https://nginx.org/en/docs/dev/development_guide.html
七 nginx哲学
非常好,非常受益。讲了思想和缘由,一定要读。(包括为什么全是异步和回调)
必须详细阅读,不可略过:http://www.aosabook.org/en/nginx.html
八 可以读源码了
读读读
九 书
代码其实没那么好读。为了效率,这本书很好:

另一本书,tengine团队编写的,我并没看,浏览目录还不错。
http://tengine.taobao.org/book/index.html#
十 更多
第三方模块列表:https://www.nginx.com/resources/wiki/modules/index.html
[dev][nginx] 在阅读nginx代码之前都需要准备什么的更多相关文章
- 《深入理解Nginx》阅读与实践(一):Nginx安装配置与HelloWorld
最近在读陶辉的<深入理解Nginx:模块开发与架构解析>,一是想跟着大牛练练阅读和编写开源代码的能力,二是想学学Nginx优秀的架构设计,三是想找一个点深入下Linux下网络编程的细节.侯 ...
- 《深入理解Nginx》阅读与实践(三):使用upstream和subrequest访问第三方服务
本文是对陶辉<深入理解Nginx>第5章内容的梳理以及实现,代码和注释基本出自此书. 一.upstream:以向nginx服务器的请求转化为向google服务器的搜索请求为例 (一)模块框 ...
- 《深入理解Nginx》阅读与实践(二):配置项的使用
前文链接:<深入理解Nginx>阅读与实践(一):Nginx安装配置与HelloWorld HelloWorld的完成意味着已经踏入了nginx的大门,虽然很振奋人心,但在编写中仍有很多疑 ...
- 《深入理解Nginx》阅读与实践(四):简单的HTTP过滤模块
一.Nginx的HTTP过滤模块特征 一个请求可以被任意个HTTP模块处理: 在普通HTTP模块处理请求完毕并调用ngx_http_send_header()发送HTTP头部或调用ngx_http_o ...
- 你连Nginx怎么转发给你请求都说不清楚,还好意思说自己不是CRUD工程师?
目录 一.Nginx工作原理二.Nginx进程模型三.Nginx处理HTTP请求流程 Nginx 工作原理 Nginx由内核和模块组成,Nginx本身做的工作实际很少,当它接到一个HTTP请求时,它仅 ...
- nginx得请求转发代码-将请求转发到网关
首先:本地主机host更改成 192.168.111.1 gulimail.com 这样一访问网址就能映射到本地. 然后修改nginx得conf worker_processes 1; events ...
- 【夯实Nginx基础】Nginx工作原理和优化、漏洞
本文地址 原文地址 本文提纲: 1. Nginx的模块与工作原理 2. Nginx的进程模型 3 . NginxFastCGI运行原理 3.1 什么是 FastCGI ...
- Nginx配置文件(nginx.conf)配置详解(2)
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...
- Nginx配置文件(nginx.conf)配置详解
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...
随机推荐
- 查找k8s版jenkins-slave官方镜像
官方镜像非常多,如果查找某个单词没有找到的话,可以换一个词查找,总之各种非常的多,带maven.djk.kubectl工具的镜像,都去试试吧, 从下面查找结果中可以看到,还有centos版的jenki ...
- [LeetCode] 73. Set Matrix Zeroes 矩阵赋零
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Exampl ...
- sshpass命令使用
1.直接远程连接某主机 sshpass -p {密码} ssh {用户名}@{主机IP} 2.远程连接指定ssh的端口 sshpass -p {密码} ssh -p ${端口} {用户名}@{主机IP ...
- jenkins:新增节点是启动方式没有Launch agent by connecting it to the master
默认在这里的配置是禁用 所以启动方式只有两种,缺少Launch agent by connecting it to the master
- xorm -Alias,Asc,Desc方法实例
Alias(string)给Table设定一个别名 package main import ( "fmt" _ "github.com/go-sql-driver/mys ...
- go 连接到数据库
package main import ( "fmt" _ "github.com/go-sql-driver/mysql" "github.com/ ...
- 【LEETCODE】42、922. Sort Array By Parity II
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 使用 Issue 管理软件项目详解
文章来源:http://www.ruanyifeng.com/blog/2017/08/issue.html 软件开发(尤其是商业软件)离不开项目管理,Issue 是最通用的管理工具之一. 本文介绍 ...
- PB Event ID 含义 内容浅析2 未公开的数据窗口事件
原网址:https://www.cnblogs.com/lenya/archive/2010/11/12/3706971.html (作者:Mark Brown) 到目前为止,P ...
- Exception: HTTP 599: SSL certificate problem: unable to get local issuer certificate 解决办法
使用Pyspider中报此错误. 错误原因: 这个错误会发生在请求 https 开头的网址,SSL 验证错误,证书有误. 解决方法: 使用self.crawl(url, callback=self.i ...