`
haoningabc
  • 浏览: 1466250 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx源码追查

阅读更多
不敢称为分析
只能叫追代码吧 根据nginx1.0.5
先看http://haoningabc.iteye.com/blog/1283098
这里有一篇
http://wenku.baidu.com/view/954455d9a58da0116c17496a.html
问题1:变量定义在哪了?那些nginx.conf里的变量
grep -nR "remote_addr" *
好多在
http/ngx_http_variables.c:147:    { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 },



8000行代码
apple:src apple$ find . -name *.c|xargs grep -v "^$"| wc -l
   80716
apple:src apple$ find . -name *.h|xargs grep -v "^$"| wc -l
    6824
apple:src apple$

按行数大小排列
wc -l */* */*/* */*/*/*  |sort -n
超过两千行的
2035 http/ngx_http_variables.c
    2070 http/ngx_http.c
    2204 core/ngx_resolver.c
    2321 event/ngx_event_openssl.c
    2799 http/modules/ngx_http_ssi_filter_module.c
    2808 http/modules/ngx_http_proxy_module.c
    2859 http/modules/ngx_http_fastcgi_module.c
    3154 http/ngx_http_request.c
    4526 http/ngx_http_upstream.c
    4543 http/ngx_http_core_module.c

最有意思的还真是最多的这两个,尤其是upstream,用epoll哦

----------
gdb nginx 1231
(gdb) l
197
198 int ngx_cdecl
199 main(int argc, char *const *argv)
200 {
----------
grep -Rn "main(int argc" *
src/core/nginx.c:199:main(int argc, char *const *argv)
找到入口
原来nginx的main函数也是按照这个统一规则建立的呀
32 static ngx_command_t  ngx_core_commands[] = {

apple:nginx-1.0.5 apple$ grep -n "ngx_string" src/core/nginx.c
26:    { ngx_string("stop"), NGX_DEBUG_POINTS_STOP },
27:    { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT },
34:    { ngx_string("daemon"),
41:    { ngx_string("master_process"),
48:    { ngx_string("timer_resolution"),
55:    { ngx_string("pid"),
62:    { ngx_string("lock_file"),
69:    { ngx_string("worker_processes"),
76:    { ngx_string("debug_points"),
83:    { ngx_string("user"),
90:    { ngx_string("worker_priority"),
97:    { ngx_string("worker_cpu_affinity"),
104:    { ngx_string("worker_rlimit_nofile"),
111:    { ngx_string("worker_rlimit_core"),
118:    { ngx_string("worker_rlimit_sigpending"),
125:    { ngx_string("working_directory"),
132:    { ngx_string("env"),
141:    { ngx_string("worker_threads"),
148:    { ngx_string("thread_stack_size"),
162:    ngx_string("core"),

这些每一个都需要细看
比如
apple:nginx-1.0.5 apple$ grep -Rn "master_process" *
Binary file objs/nginx matches
Binary file objs/src/core/nginx.o matches
Binary file objs/src/os/unix/ngx_process_cycle.o matches
src/core/nginx.c:41:    { ngx_string("master_process"),
src/core/nginx.c:405:        ngx_master_process_cycle(cycle);
src/os/unix/ngx_process_cycle.c:20:static void ngx_master_process_exit(ngx_cycle_t *cycle);
src/os/unix/ngx_process_cycle.c:65:static u_char  master_process[] = "master process";
src/os/unix/ngx_process_cycle.c:83:ngx_master_process_cycle(ngx_cycle_t *cycle)
src/os/unix/ngx_process_cycle.c:117:    size = sizeof(master_process);
src/os/unix/ngx_process_cycle.c:125:    p = ngx_cpymem(title, master_process, sizeof(master_process) - 1);
src/os/unix/ngx_process_cycle.c:184:            ngx_master_process_exit(cycle);
src/os/unix/ngx_process_cycle.c:321:            ngx_master_process_exit(cycle);
src/os/unix/ngx_process_cycle.c:679:ngx_master_process_exit(ngx_cycle_t *cycle)
src/os/unix/ngx_process_cycle.h:36:void ngx_master_process_cycle(ngx_cycle_t *cycle);
apple:nginx-1.0.5 apple$ 

apple:src apple$ tree
.
├── core
│   ├── nginx.c
│   ├── nginx.h
│   ├── ngx_array.c
│   ├── ngx_array.h
│   ├── ngx_buf.c
│   ├── ngx_buf.h
│   ├── ngx_conf_file.c
│   ├── ngx_conf_file.h
│   ├── ngx_config.h
│   ├── ngx_connection.c
│   ├── ngx_connection.h
│   ├── ngx_core.h
│   ├── ngx_cpuinfo.c
│   ├── ngx_crc.h
│   ├── ngx_crc32.c
│   ├── ngx_crc32.h
│   ├── ngx_crypt.c
│   ├── ngx_crypt.h
│   ├── ngx_cycle.c
│   ├── ngx_cycle.h
│   ├── ngx_file.c
│   ├── ngx_file.h
│   ├── ngx_hash.c
│   ├── ngx_hash.h
│   ├── ngx_inet.c
│   ├── ngx_inet.h
│   ├── ngx_list.c
│   ├── ngx_list.h
│   ├── ngx_log.c
│   ├── ngx_log.h
│   ├── ngx_md5.c
│   ├── ngx_md5.h
│   ├── ngx_murmurhash.c
│   ├── ngx_murmurhash.h
│   ├── ngx_open_file_cache.c
│   ├── ngx_open_file_cache.h
│   ├── ngx_output_chain.c
│   ├── ngx_palloc.c
│   ├── ngx_palloc.h
│   ├── ngx_parse.c
│   ├── ngx_parse.h
│   ├── ngx_queue.c
│   ├── ngx_queue.h
│   ├── ngx_radix_tree.c
│   ├── ngx_radix_tree.h
│   ├── ngx_rbtree.c
│   ├── ngx_rbtree.h
│   ├── ngx_regex.c
│   ├── ngx_regex.h
│   ├── ngx_resolver.c
│   ├── ngx_resolver.h
│   ├── ngx_sha1.h
│   ├── ngx_shmtx.c
│   ├── ngx_shmtx.h
│   ├── ngx_slab.c
│   ├── ngx_slab.h
│   ├── ngx_spinlock.c
│   ├── ngx_string.c
│   ├── ngx_string.h
│   ├── ngx_times.c
│   └── ngx_times.h
├── event
│   ├── modules
│   │   ├── ngx_aio_module.c
│   │   ├── ngx_devpoll_module.c
│   │   ├── ngx_epoll_module.c
│   │   ├── ngx_eventport_module.c
│   │   ├── ngx_kqueue_module.c
│   │   ├── ngx_poll_module.c
│   │   ├── ngx_rtsig_module.c
│   │   ├── ngx_select_module.c
│   │   └── ngx_win32_select_module.c
│   ├── ngx_event.c
│   ├── ngx_event.h
│   ├── ngx_event_accept.c
│   ├── ngx_event_busy_lock.c
│   ├── ngx_event_busy_lock.h
│   ├── ngx_event_connect.c
│   ├── ngx_event_connect.h
│   ├── ngx_event_mutex.c
│   ├── ngx_event_openssl.c
│   ├── ngx_event_openssl.h
│   ├── ngx_event_pipe.c
│   ├── ngx_event_pipe.h
│   ├── ngx_event_posted.c
│   ├── ngx_event_posted.h
│   ├── ngx_event_timer.c
│   └── ngx_event_timer.h
├── http
│   ├── modules
│   │   ├── ngx_http_access_module.c
│   │   ├── ngx_http_addition_filter_module.c
│   │   ├── ngx_http_auth_basic_module.c
│   │   ├── ngx_http_autoindex_module.c
│   │   ├── ngx_http_browser_module.c
│   │   ├── ngx_http_charset_filter_module.c
│   │   ├── ngx_http_chunked_filter_module.c
│   │   ├── ngx_http_dav_module.c
│   │   ├── ngx_http_degradation_module.c
│   │   ├── ngx_http_empty_gif_module.c
│   │   ├── ngx_http_fastcgi_module.c
│   │   ├── ngx_http_flv_module.c
│   │   ├── ngx_http_geo_module.c
│   │   ├── ngx_http_geoip_module.c
│   │   ├── ngx_http_gzip_filter_module.c
│   │   ├── ngx_http_gzip_static_module.c
│   │   ├── ngx_http_headers_filter_module.c
│   │   ├── ngx_http_image_filter_module.c
│   │   ├── ngx_http_index_module.c
│   │   ├── ngx_http_limit_req_module.c
│   │   ├── ngx_http_limit_zone_module.c
│   │   ├── ngx_http_log_module.c
│   │   ├── ngx_http_map_module.c
│   │   ├── ngx_http_memcached_module.c
│   │   ├── ngx_http_not_modified_filter_module.c
│   │   ├── ngx_http_proxy_module.c
│   │   ├── ngx_http_random_index_module.c
│   │   ├── ngx_http_range_filter_module.c
│   │   ├── ngx_http_realip_module.c
│   │   ├── ngx_http_referer_module.c
│   │   ├── ngx_http_rewrite_module.c
│   │   ├── ngx_http_scgi_module.c
│   │   ├── ngx_http_secure_link_module.c
│   │   ├── ngx_http_split_clients_module.c
│   │   ├── ngx_http_ssi_filter_module.c
│   │   ├── ngx_http_ssi_filter_module.h
│   │   ├── ngx_http_ssl_module.c
│   │   ├── ngx_http_ssl_module.h
│   │   ├── ngx_http_static_module.c
│   │   ├── ngx_http_stub_status_module.c
│   │   ├── ngx_http_sub_filter_module.c
│   │   ├── ngx_http_upstream_ip_hash_module.c
│   │   ├── ngx_http_userid_filter_module.c
│   │   ├── ngx_http_uwsgi_module.c
│   │   ├── ngx_http_xslt_filter_module.c
│   │   └── perl
│   │       ├── Makefile.PL
│   │       ├── nginx.pm
│   │       ├── nginx.xs
│   │       ├── ngx_http_perl_module.c
│   │       ├── ngx_http_perl_module.h
│   │       └── typemap
│   ├── ngx_http.c
│   ├── ngx_http.h
│   ├── ngx_http_busy_lock.c
│   ├── ngx_http_busy_lock.h
│   ├── ngx_http_cache.h
│   ├── ngx_http_config.h
│   ├── ngx_http_copy_filter_module.c
│   ├── ngx_http_core_module.c
│   ├── ngx_http_core_module.h
│   ├── ngx_http_file_cache.c
│   ├── ngx_http_header_filter_module.c
│   ├── ngx_http_parse.c
│   ├── ngx_http_parse_time.c
│   ├── ngx_http_postpone_filter_module.c
│   ├── ngx_http_request.c
│   ├── ngx_http_request.h
│   ├── ngx_http_request_body.c
│   ├── ngx_http_script.c
│   ├── ngx_http_script.h
│   ├── ngx_http_special_response.c
│   ├── ngx_http_upstream.c
│   ├── ngx_http_upstream.h
│   ├── ngx_http_upstream_round_robin.c
│   ├── ngx_http_upstream_round_robin.h
│   ├── ngx_http_variables.c
│   ├── ngx_http_variables.h
│   └── ngx_http_write_filter_module.c
├── mail
│   ├── ngx_mail.c
│   ├── ngx_mail.h
│   ├── ngx_mail_auth_http_module.c
│   ├── ngx_mail_core_module.c
│   ├── ngx_mail_handler.c
│   ├── ngx_mail_imap_handler.c
│   ├── ngx_mail_imap_module.c
│   ├── ngx_mail_imap_module.h
│   ├── ngx_mail_parse.c
│   ├── ngx_mail_pop3_handler.c
│   ├── ngx_mail_pop3_module.c
│   ├── ngx_mail_pop3_module.h
│   ├── ngx_mail_proxy_module.c
│   ├── ngx_mail_smtp_handler.c
│   ├── ngx_mail_smtp_module.c
│   ├── ngx_mail_smtp_module.h
│   ├── ngx_mail_ssl_module.c
│   └── ngx_mail_ssl_module.h
├── misc
│   ├── ngx_cpp_test_module.cpp
│   └── ngx_google_perftools_module.c
└── os
    └── unix
        ├── ngx_aio_read.c
        ├── ngx_aio_read_chain.c
        ├── ngx_aio_write.c
        ├── ngx_aio_write_chain.c
        ├── ngx_alloc.c
        ├── ngx_alloc.h
        ├── ngx_atomic.h
        ├── ngx_channel.c
        ├── ngx_channel.h
        ├── ngx_daemon.c
        ├── ngx_darwin.h
        ├── ngx_darwin_config.h
        ├── ngx_darwin_init.c
        ├── ngx_darwin_sendfile_chain.c
        ├── ngx_errno.c
        ├── ngx_errno.h
        ├── ngx_file_aio_read.c
        ├── ngx_files.c
        ├── ngx_files.h
        ├── ngx_freebsd.h
        ├── ngx_freebsd_config.h
        ├── ngx_freebsd_init.c
        ├── ngx_freebsd_rfork_thread.c
        ├── ngx_freebsd_rfork_thread.h
        ├── ngx_freebsd_sendfile_chain.c
        ├── ngx_gcc_atomic_amd64.h
        ├── ngx_gcc_atomic_ppc.h
        ├── ngx_gcc_atomic_sparc64.h
        ├── ngx_gcc_atomic_x86.h
        ├── ngx_linux.h
        ├── ngx_linux_aio_read.c
        ├── ngx_linux_config.h
        ├── ngx_linux_init.c
        ├── ngx_linux_sendfile_chain.c
        ├── ngx_os.h
        ├── ngx_posix_config.h
        ├── ngx_posix_init.c
        ├── ngx_process.c
        ├── ngx_process.h
        ├── ngx_process_cycle.c
        ├── ngx_process_cycle.h
        ├── ngx_pthread_thread.c
        ├── ngx_readv_chain.c
        ├── ngx_recv.c
        ├── ngx_send.c
        ├── ngx_setproctitle.c
        ├── ngx_setproctitle.h
        ├── ngx_shmem.c
        ├── ngx_shmem.h
        ├── ngx_socket.c
        ├── ngx_socket.h
        ├── ngx_solaris.h
        ├── ngx_solaris_config.h
        ├── ngx_solaris_init.c
        ├── ngx_solaris_sendfilev_chain.c
        ├── ngx_sunpro_amd64.il
        ├── ngx_sunpro_atomic_sparc64.h
        ├── ngx_sunpro_sparc64.il
        ├── ngx_sunpro_x86.il
        ├── ngx_thread.h
        ├── ngx_time.c
        ├── ngx_time.h
        ├── ngx_udp_recv.c
        ├── ngx_user.c
        ├── ngx_user.h
        ├── ngx_writev_chain.c
        └── rfork_thread.S

10 directories, 251 files
apple:src apple$ 
分享到:
评论

相关推荐

    nginx源码剖析

    nginx源码说明;其他下载即可,没下载分了,大家互相帮忙。其他情况大概就这些吧,其他也没什么好说的了,看文档即可

    nginx源码 1.18版

    源码分析有助于深入理解其工作原理,优化性能或进行...通过深入学习和分析Nginx源码,开发者可以提升自己的网络编程能力,更好地理解和解决实际问题,如性能瓶颈、安全漏洞等,同时为自定义开发Nginx模块打下坚实基础。

    nginx源码包安装后设置开机自启.docx

    nginx源码包安装后设置开机自启 在 Linux 系统中,源码安装的软件默认无法使用 systemd 管理,而 systemd 是 Linux 系统中最常用的进程管理工具之一。因此,如果需要使用 systemd 管理源码安装的软件,需要手动编写...

    nginx源码学习资料

    **Nginx源码学习资料概述** Nginx是一款高性能的HTTP和反向代理服务器,以其轻量级、高并发处理能力以及优秀的稳定性而受到广大Web开发者和运维人员的青睐。学习Nginx源码有助于深入理解其工作原理,提高在实际应用...

    nginx各版本源码包

    **Nginx 各版本源码包详解** Nginx 是一款高性能的 Web 和反向代理服务器,广泛应用于互联网行业中,以其高效的并发处理能力、低内存占用和丰富的模块支持而备受青睐。本压缩包提供了 Nginx 的四个不同版本源码,...

    nginx 源码 解析 资料大全

    收集的 nginx 源码 解析 ,非常全 architecture.png Emiller的Nginx模块开发指南.docx Nginx(en).pdf nginx@taobao.pdf nginx_internals.pdf ...nginx源码分析.doc nginx源码剖析.pdf Ningx代码研究.docx

    nginx源码windows版

    **Nginx源码在Windows下的编译与运行** Nginx是一款高性能的Web服务器及反向代理服务器,因其高效、稳定以及丰富的模块支持而广受欢迎。在Windows环境下,尽管Nginx通常被认为更适合在Linux系统中运行,但通过...

    Nginx源码安装手册

    下面将详细介绍Nginx源码安装手册中所涵盖的知识点。 首先,系统环境的配置是安装任何软件前需要确认的基础。本手册中提到的Nginx版本是1.6.3,操作系统为CentOS 6.7 64位。这说明了要安装的Nginx版本和操作系统...

    带有注释的nginx源码

    **标题:“带有注释的nginx源码”** **描述:“带有详细注释的nginx源码,能帮你有效地阅读和学习nginx源码”** 这是一份包含丰富注释的nginx源码,非常适合那些想要深入理解这款高性能HTTP和反向代理服务器工作...

    nginx源码 rtmp-module 源码 及编译方法

    **Nginx源码分析与RTMP模块编译** Nginx是一款高性能的Web服务器,以其反向代理、负载均衡和静态文件处理能力而闻名。它采用事件驱动模型,能够高效地处理高并发请求,是许多网站和流媒体服务的首选解决方案。在本...

    nginx源码安装方法

    ### Nginx源码安装详解 #### 一、前言 Nginx是一款高性能的HTTP服务器及反向代理服务软件,被广泛应用于互联网行业。它以其稳定、快速、占用资源少等特点深受用户喜爱。本文将详细介绍如何通过源码安装Nginx,并...

    1.0版本的nginx源码

    **1.0版本的Nginx源码** 1.0 版本的 Nginx 源码可能相对较旧,但它是 Nginx 发展历程中的一个重要里程碑。这个版本包含了许多基本特性和功能,如静态文件服务、HTTP/1.1 协议支持、反向代理、负载均衡等。通过研究...

    nginx源码安装

    **Nginx源码安装详解** Nginx是一款高性能的HTTP和反向代理服务器,以其轻量级、高并发处理能力和稳定性而广受赞誉。在Linux系统中,我们经常需要通过源码安装来获取最新版或者定制化配置的Nginx服务。下面将详细...

    Nginx源码下载

    2017年3月27日更新的Nginx源码意味着这个版本包含了当时的最新特性和修复,可能是对性能优化、安全性改进或者新功能的添加。 Nginx的源码下载通常用于自定义编译,以适应特定的系统环境或需求。以下是一些关于Nginx...

    nginx源码包(nginx+pcre+openssl+zlib)

    **Nginx** 是一款高性能的 Web 和反向代理服务器,以其轻量级、高并发、稳定性和灵活性而闻名。Nginx 的源代码由多个组件组成,包括基础的 Nginx 引擎以及与其他软件的集成,如 PCRE(Perl Compatible Regular ...

    nginx源码分析--带注释

    在本文中,我们将深入探讨Nginx的源代码分析,主要关注那些被特别注释的部分,以帮助我们更好地理解和利用这个高性能的Web...因此,花时间研究和注释Nginx源码对于任何希望深入掌握Nginx的人来说都是极其有价值的投资。

Global site tag (gtag.js) - Google Analytics