nginx源码追查

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


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

按行数大小排列
[color=red]wc -l */* */*/* */*/*/* |sort -n[/color]
超过两千行的

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哦

----------
[color=red]gdb nginx 1231[/color]
(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)
[color=red]找到入口[/color]
原来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$
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值