今天用了一天的时间看nginx的启动流程,流程还是很复杂,主要的函数调用有十几个之多,通过看源码和上网查资料,弄懂了一些函数,有些函数还在学习中,有些函数还待日后学习,这里记录一下今天所学。加油!
http://blog.csdn.net/xiaoliangsky/article/details/39856803
1nginx.c
启动的程序主要在src/core/nginx.c中,和普通函数一样,main函数是其入口函数:下面我们看看main函数的源代码:
int ngx_cdecl
main(int argc, char *const *argv)
{
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
ngx_core_conf_t *ccf;
#if (NGX_FREEBSD)
ngx_debug_init();
#endif
//该函数的定义在文件src/os/unix/ngx_errno.c,初始化错误编码
if (ngx_strerror_init() != NGX_OK) {
return 1;
}
if (ngx_get_options(argc, argv) != NGX_OK) {//解析Nginx的启动参数
return 1;
}
if (ngx_show_version) {
ngx_write_stderr("nginx version: " NGINX_VER NGX_LINEFEED);
if (ngx_show_help) {//启动配置参数
ngx_write_stderr(
"Usage: nginx [-?hvVtq] [-s signal] [-c filename] "
"[-p prefix] [-g directives]" NGX_LINEFEED
NGX_LINEFEED
"Options:" NGX_LINEFEED
" -?,-h : this help" NGX_LINEFEED
" -v : show version and exit" NGX_LINEFEED
" -V : show version and configure options then exit"
NGX_LINEFEED
" -t : test configuration and exit" NGX_LINEFEED
" -q : suppress non-error messages "
"during configuration testing" NGX_LINEFEED
" -s sign

本文详细介绍了nginx的启动过程,从ngx_strerror_init()初始化错误信息,到ngx_init_cycle()进行大部分初始化操作,再到ngx_create_pidfile()创建进程记录文件。过程中涉及参数解析、时间初始化、正则表达式、日志、SSL、信号处理等多个关键步骤,揭示了nginx启动背后的复杂性和高效性。
最低0.47元/天 解锁文章
1021

被折叠的 条评论
为什么被折叠?



