annotated_nginx icon indicating copy to clipboard operation
annotated_nginx copied to clipboard

Annotated Nginx Source(中文)

annotated_nginx

Annotated Nginx Source(中文)

简介

Nginx源码分析,注解代码,帮助学习Nginx。

  • 1.10增加了动态模块、http2、reuseport。
  • 1.11.x里的stream模块的变动较大,完善了阶段处理。
  • 1.14增加了mirror模块,支持gRPC。
  • 1.15.10增加了range listen,指令“ssl_certificate”可从变量里加载证书。
  • 1.17.0不再支持OpenSSL 0.98,limit_rate/proxy_upload_rate支持变量。
  • 1.21.4支持内核TLS(kTLS),要求使用OpenSSL3.0,Linux内核高于4.17。
  • 1.21.5支持更新的PCRE2,但向上的封装接口不变。

请参考:

当前状态

Nginx 1.23.1

Git分支

分支 说明 注释
master Nginx开发版1.23.1
mainline Nginx开发版1.23.1
stable Nginx稳定版1.22.0

已注解

源码目录快捷入口

  • src - 70%,nginx源码目录
  • core - 90%,md5/sha1/crc等较简单的功能不关注
  • event - 90%,只注解核心模块和epoll,select/kqueue/ssl等不关注
  • http - 70%,少量modules目录里的具体功能模块有注释
  • os/unix - 80%,bsd/darwin/solaris等系统不关注
  • stream - 70%
  • misc - 100%

UML图解

UML图示

部分关键源码(目录分类)

core目录
  • nginx.c
  • ngx_conf_file.h
  • ngx_module.h
  • ngx_module.c
  • ngx_connection.h
  • ngx_connection.c
  • ngx_thread_pool.h
  • ngx_thread_pool.c
  • ngx_palloc.c
  • ngx_slab.c
  • ngx_log.c
event目录
  • ngx_event.h
  • ngx_event.c
  • ngx_event_accept.c
  • ngx_event_timer.c
  • ngx_epoll_module.c
http目录
  • ngx_http.h
  • ngx_http.c
  • ngx_http_core_module.h
  • ngx_http_core_module.c
  • ngx_http_request.h
  • ngx_http_request.c
  • ngx_http_request_body.c
  • ngx_http_header_filter_module.c
  • ngx_http_write_filter_module.c
http/modules目录
  • ngx_http_limit_req_module.c 红黑树和共享内存的使用示例
  • ngx_http_degradation_module.c
  • ngx_http_upstream_zone_module.c
  • ngx_http_mirror_module.c
os/unix目录
  • ngx_os.h
  • ngx_process.c
  • ngx_process_cycle.c
  • ngx_writev_chain.c
stream目录
  • ngx_stream.h
  • ngx_stream.c
  • ngx_stream_core_module.c
  • ngx_stream_handler.c
misc目录
  • ngx_google_perftools_module.c

部分关键源码(功能分类)

内存管理
  • ngx_palloc.c
  • ngx_slab.c
  • ngx_http_limit_req_module.c 红黑树和共享内存的使用示例
  • ngx_http_degradation_module.c
  • ngx_http_upstream_zone_module.c
数据结构
  • ngx_array.h
  • ngx_list.h
  • ngx_string.h
  • ngx_buf.h
  • ngx_rbtree.h
  • ngx_http_limit_req_module.c 红黑树和共享内存的使用示例
进程机制
  • nginx.c
  • ngx_conf_file.h
  • ngx_module.h
  • ngx_module.c
  • ngx_process.c
  • ngx_process_cycle.c
事件机制
  • ngx_connection.h
  • ngx_connection.c
  • ngx_event.h
  • ngx_event.c
  • ngx_event_accept.c
  • ngx_event_timer.c
  • ngx_epoll_module.c
多线程机制
  • ngx_event.h
  • ngx_event.c
  • ngx_thread_pool.h
  • ngx_thread_pool.c
tcp(stream)处理
  • ngx_connection.h
  • ngx_connection.c
  • ngx_stream.h
  • ngx_stream.c
  • ngx_stream_core_module.c
  • ngx_stream_handler.c
http处理
  • ngx_connection.h
  • ngx_connection.c
  • ngx_http.h
  • ngx_http.c
  • ngx_http_core_module.h
  • ngx_http_core_module.c
  • ngx_http_request.h
  • ngx_http_request.c
  • ngx_http_request_body.c
  • ngx_http_header_filter_module.c
  • ngx_http_write_filter_module.c

不注解

  • auto
  • mail