Nginx之main初探ngx_init_cycle()(上)

Nginx之main初探ngx_init_cycle()(上)

由于ngx_init_cycle()函数非常庞大,这里只给出前400+行的函数调用关系,后400+将在后面的文章中给出。

-->ngx_init_cycle(&init_cycle)
	    -->ngx_timezone_update()
		    -->time()
			-->localtime()注1:
		-->ngx_timeofday()
		-->ngx_time_update()
		    -->ngx_gettimeofday() -- gettimeofday()
			-->ngx_gmtime()
			-->ngx_localtime()
			-->ngx_memory_barrier()
		-->ngx_increase_pipe_generation()
		-->ngx_create_pool()
			-->ngx_memalign() --  ngx_alloc(size, log)
		-->ngx_pcalloc()
		    -->ngx_palloc()
			    -->ngx_align_ptr()注2:
			    -->ngx_palloc_block()
			        -->ngx_memalign()
				    -->ngx_align_ptr()
			    -->ngx_palloc_large()
			        -->ngx_alloc()
				        -->malloc()
				    -->ngx_palloc()	
			-->ngx_memzero()
			    -->memset()
		-->ngx_list_init()
		    -->ngx_palloc()
		-->ngx_queue_init()
		-->ngx_strlen() -- strlen()
		-->ngx_pnalloc()
		    -->ngx_palloc_block()
			-->ngx_palloc_large()
		-->ngx_strlow()
		    -->ngx_tolower() -- ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
		-->ngx_array_create()
		    -->ngx_palloc()
			-->ngx_array_init()
			    -->ngx_palloc()
		-->ngx_conf_param()
		    -->ngx_memzero()
			-->ngx_conf_parse()
		-->ngx_conf_parse()
		    -->ngx_open_file()  -- open()
			-->ngx_fd_info()  -- fstat()
			-->ngx_alloc()
			-->ngx_conf_read_token()
			    -->ngx_file_size()
				-->ngx_memmove()  --  memmove()
				-->ngx_read_file()   -- read()
				-->ngx_write_console() -- ngx_write_fd()
				    --> write()
				-->ngx_array_push()
			-->ngx_conf_handler()
		-->ngx_show_dso_directives()
		    -->ngx_get_conf()
		-->ngx_is_dynamic_module()
		    -->ngx_get_conf()
		-->ngx_test_lockfile()
		    -->ngx_open_file()
			-->ngx_close_file()
			-->ngx_delete_file()
		-->ngx_create_paths()
		    -->ngx_create_dir() -- mkdir()
			-->ngx_file_info()
		-->ngx_log_open_default()
		    -->ngx_conf_open_file()

下面是陌生函数的用法和小知识点:

注1:time()与localtime()函数不是Nginx自己实现的,是库函数。其用法如下

/**
	 * filename:    test_localtime.c
	 * description: used to see the usage of function localtime()
	 * date:        2015-03-06
	 * author:      HowardKing
	 * version:     1.0
	 */


	#include <stdio.h>
	#include <stdlib.h>
	#include <time.h>


	int main(void)
	{
			time_t timer; // time_t is long int
			struct tm *tblock;


			time(NULL);
			tblock = localtime(&timer);
			printf("Local time is: %s", asctime(tblock));


			return 0;
	}


程序输出结果:
<span style="white-space:pre">	</span>Local time is: Fri Jul 31 05:00:00 4461676



注2:C语言中long类型是与机器字长相对应的,而int型来说一般都是4字节。

/**
	 * filename:    test_unsigned_long.c
	 * description: find out the size of type long
	 * date:        20150306
	 * author:      HowardKing
	 * version:     v1.0
	 */


	#include <stdio.h>
	#include <stdlib.h>


	int main(void)
	{
			int ii = 100;
			unsigned long ll = 100;


			printf("%d\n", sizeof(ii));
			printf("%d\n", sizeof(ll));


			return 0;
	}


程序输出结果:
	4
	8


  • 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、付费专栏及课程。

余额充值