nginx中ngx

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

ngx_cycle_t

是结构体ngx_cycle_s的别名

typedef struct ngx_cycle_s           ngx_cycle_t;

结构体ngx_cycle_s的定义

struct ngx_cycle_s {
    void                  ****conf_ctx;
    ngx_pool_t               *pool;

    ngx_log_t                *log;
    ngx_log_t                 new_log;

    ngx_uint_t                log_use_stderr;  /* unsigned  log_use_stderr:1; */

    ngx_connection_t        **files;
    ngx_connection_t         *free_connections;
    ngx_uint_t                free_connection_n;

    ngx_module_t            **modules;
    ngx_uint_t                modules_n;
    ngx_uint_t                modules_used;    /* unsigned  modules_used:1; */

    ngx_queue_t               reusable_connections_queue;
    ngx_uint_t                reusable_connections_n;
    time_t                    connections_reuse_time;

    ngx_array_t               listening;
    ngx_array_t               paths;

    ngx_array_t               config_dump;
    ngx_rbtree_t              config_dump_rbtree;
    ngx_rbtree_node_t         config_dump_sentinel;

    ngx_list_t                open_files;
    ngx_list_t                shared_memory;

    ngx_uint_t                connection_n;
    ngx_uint_t                files_n;

    ngx_connection_t         *connections;
    ngx_event_t              *read_events;
    ngx_event_t              *write_events;

    ngx_cycle_t              *old_cycle;

    ngx_str_t                 conf_file;
    ngx_str_t                 conf_param;
    ngx_str_t                 conf_prefix;
    ngx_str_t                 prefix;
    ngx_str_t                 error_log;
    ngx_str_t                 lock_file;
    ngx_str_t                 hostname;
};

conf_ctx

创建

在ngx_init_cycle中创建conf_ctx分配内存。创建ngx_max_module个void* 内存块

cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
    if (cycle->conf_ctx == NULL) {
        ngx_destroy_pool(pool);
        return NULL;
    }

第一次赋值

模块类型为CORE_MODULE调用核心模块的create_conf方法来分配内存

for (i = 0; cycle->modules[i]; i++) {
        if (cycle->modules[i]->type != NGX_CORE_MODULE) {
            continue;
        }

        module = cycle->modules[i]->ctx;

        if (module->create_conf) {
            rv = module->create_conf(cycle);
            if (rv == NULL) {
                ngx_destroy_pool(pool);
                return NULL;
            }
            cycle->conf_ctx[cycle->modules[i]->index] = rv;
        }
    }

核心模块中有create_conf的模块有

模块

create_conf方法

ngx_core_module

ngx_core_module_create_conf

ngx_openssl_module

ngx_openssl_create_conf

ngx_google_perftools_module

ngx_google_perftools_create_conf

ngx_regex_module

ngx_regex_create_conf

ngx_thread_pool_module

ngx_thread_pool_create_conf

解析模块类型为CORE_MODULE且命令类型为NGX_MAIN_CONF

模块

命令名

命令处理

ngx_core_module

daemon

ngx_conf_set_flag_slot

master_process

ngx_conf_set_flag_slot

timer_resolution

ngx_conf_set_msec_slot

pid

ngx_conf_set_str_slot

lock_file

ngx_conf_set_str_slot

worker_processes

ngx_set_worker_processes

debug_points

ngx_conf_set_enum_slot

user

ngx_set_user

worker_priority

ngx_set_priority

worker_cpu_affinity

ngx_set_cpu_affinity

worker_rlimit_nofile

ngx_conf_set_num_slot

worker_rlimit_core

ngx_conf_set_off_slot

worker_shutdown_timeout

ngx_conf_set_msec_slot

working_directory

ngx_conf_set_str_slot

env

ngx_set_env

load_module

ngx_load_module

ngx_events_module

events

ngx_events_block

ngx_openssl_module

ssl_engine

ngx_openssl_engine

ngx_google_perftools_module

google_perftools_profiles

ngx_conf_set_str_slot

ngx_http_module

http

ngx_http_block

ngx_errlog_module

error_log

ngx_error_log

ngx_mail_module

mail

ngx_mail_block

ngx_regex_module

pcre_jit

ngx_conf_set_flag_slot

ngx_stream_module

stream

ngx_stream_block

ngx_thread_pool_module

thread_pool

ngx_thread_pool

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginx