Nginx函数ngx_single_process_cycle学习笔记

  • ngx_cycle_t=ngx_cycle_s
    ngx_cycle_s的定义如下,下面介绍的函数中有一个重要的ngx_cycle_t类型的参数cycle,所一写介绍下它的类型结构。
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_array_t               listening;
ngx_array_t               paths;
ngx_array_t               config_dump;
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                 lock_file;
ngx_str_t                 hostname;
};
  • ngx_module_t=ngx_module_s
    在ngx_cycle_s中modules成员类型如下
    说明:ngx_module_t表示Nginx模块的基本接口,针对每个不同类型的模块,都有一个结构提来描述这一类模块的通用接口,这个接口保存在ngx_module_t的ctx成员中。例如核心模块的通用接口是ngx_core_model_t结构体,而事件模块的通用接口则是ngx_event_module_t
struct ngx_module_s {
ngx_uint_t            ctx_index;
ngx_uint_t            index;
char                 *name;
ngx_uint_t            spare0;
ngx_uint_t            spare1;
ngx_uint_t            version;
const char           *signature;
void                 *ctx;
ngx_command_t        *commands;
ngx_uint_t            type;
ngx_int_t           (*init_master)(ngx_log_t *log);
ngx_int_t           (*init_module)(ngx_cycle_t *cycle);
ngx_int_t           (*init_process)(ngx_cycle_t *cycle);
ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);
void                (*exit_thread)(ngx_cycle_t *cycle);
void                (*exit_process)(ngx_cycle_t *cycle);
void                (*exit_master)(ngx_cycle_t *cycle);
uintptr_t             spare_hook0;
uintptr_t             spare_hook1;
uintptr_t             spare_hook2;
uintptr_t             spare_hook3;
uintptr_t             spare_hook4;
uintptr_t             spare_hook5;
uintptr_t             spare_hook6;
uintptr_t             spare_hook7;
};

//ctx指向以下的ngx_event_module_t
typedef struct 
{
ngx_str_t              *name;
void                 *(*create_conf)(ngx_cycle_t *cycle);
char                 *(*init_conf)(ngx_cycle_t *cycle, void *conf);
ngx_event_actions_t     actions;
} ngx_event_module_t;

//ngx_command_t的定义如下
struct ngx_command_s {
ngx_str_t             name;
ngx_uint_t            type;
char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
ngx_uint_t            conf;
ngx_uint_t            offset;
void                 *post;
};
  • ngx_process_events
    在void ngx_process_events_and_timers(ngx_cycle_t *cycle)方法中,ngx_process_events的定义如下
    ngx_process_events实际对应的函数为:static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
define ngx_process_events ngx_event_actions.process_events
ngx_event_actions_t   ngx_event_actions;
typedef struct {
ngx_int_t  (*add)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);
ngx_int_t  (*del)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);
ngx_int_t  (*enable)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);
ngx_int_t  (*disable)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);
ngx_int_t  (*add_conn)(ngx_connection_t *c);
ngx_int_t  (*del_conn)(ngx_connection_t *c, ngx_uint_t flags);
ngx_int_t  (*notify)(ngx_event_handler_pt handler);
ngx_int_t  (*process_events)(ngx_cycle_t *cycle, ngx_msec_t timer,
ngx_uint_t flags);
ngx_int_t  (*init)(ngx_cycle_t *cycle, ngx_msec_t timer);
void       (*done)(ngx_cycle_t *cycle);
} ngx_event_actions_t;
  • ngx_set_environment

  • init_process

  • ngx_log_debug0

  • ngx_process_events_and_timers

  • exit_process

  • ngx_master_process_exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Nginx 中安装 ngx_http_mp4_module 模块,需要按照以下步骤进行操作: 1. 确认 Nginx 是否支持 ngx_http_mp4_module 模块 首先需要确认 Nginx 是否支持 ngx_http_mp4_module 模块,可以使用以下命令查看 Nginx 是否已经编译了该模块: ``` nginx -V 2>&1 | grep -o with-http_mp4_module ``` 如果输出结果为 with-http_mp4_module,则说明 Nginx 已经编译了 ngx_http_mp4_module 模块;如果输出结果为空,则说明 Nginx 没有编译该模块。 2. 下载 ngx_http_mp4_module 模块 如果 Nginx 没有编译 ngx_http_mp4_module 模块,需要下载该模块并添加到 Nginx 中。可以从 Github 上下载该模块,链接为:https://github.com/kaltura/nginx-vod-module。 可以使用以下命令将 ngx_http_mp4_module 模块下载到 /opt 目录下: ``` cd /opt git clone https://github.com/kaltura/nginx-vod-module.git ``` 3. 编译 Nginx 并添加 ngx_http_mp4_module 模块 在编译 Nginx 时需要添加 --add-module=/opt/nginx-vod-module 参数来指定 ngx_http_mp4_module 模块所在的目录,具体命令如下: ``` ./configure --prefix=/usr/local/nginx --add-module=/opt/nginx-vod-module make make install ``` 4. 配置 NginxNginx 的配置文件中添加以下内容,即可使用 ngx_http_mp4_module 模块: ``` location /video/ { mp4; mp4_buffer_size 1m; mp4_max_buffer_size 5m; } ``` 其中,/video/ 是视频文件所在的目录。mp4 是 ngx_http_mp4_module 模块提供的指令,表示该目录下的文件都是 MP4 格式的视频文件。 mp4_buffer_size 和 mp4_max_buffer_size 是 ngx_http_mp4_module 模块提供的两个参数,用于控制视频文件的缓存大小。 5. 重启 Nginx 完成以上步骤后,需要重启 Nginx 使配置生效: ``` nginx -s reload ``` 至此,ngx_http_mp4_module 模块安装完成。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值