访问新浪时,时常会有一些网页返回空白(但不是“此页无法显示”),从浏览器的信息中可以知道此时服务器返回了一个1×1的空白gif图片。
这实际上是 nginx实现的, nginx有一个名为Empty Gif的module,专门负责此项工作。
由于这个module比较简单,我们就先从它入手,来看看 nginx的模块实现。
这个文件比较简单,一开始定义并初始化了3个变量。
static ngx_command_t ngx_http_empty_gif_commands[] = {...};
static ngx_http_module_t ngx_http_empty_gif_module_ctx = {...};
ngx_module_t ngx_http_empty_gif_module = {...};
其中只有ngx_http_empty_gif_module是非静态的,我将暂时将其称为module主结构变量,
而其余两个变量都可以由它访问到。
但是如果继续查看 nginx的源码,会发现没有其他地方引用ngx_http_empty_gif_module,
那这个module是怎么注册并应用起来的呢?
如果熟悉 Apache的代码,会发现这和 Apache 2.0的module机制非常类似——每个module都对应到一个module主结构变量,通过这个主结构变量可以访问到这个module的其他内容,该modu
这实际上是 nginx实现的, nginx有一个名为Empty Gif的module,专门负责此项工作。
由于这个module比较简单,我们就先从它入手,来看看 nginx的模块实现。
模块注册
Empty Gif这个module只有一个文件—— ngx_http_empty_gif_module.c这个文件比较简单,一开始定义并初始化了3个变量。
static ngx_command_t ngx_http_empty_gif_commands[] = {...};
static ngx_http_module_t ngx_http_empty_gif_module_ctx = {...};
ngx_module_t ngx_http_empty_gif_module = {...};
其中只有ngx_http_empty_gif_module是非静态的,我将暂时将其称为module主结构变量,
而其余两个变量都可以由它访问到。
但是如果继续查看 nginx的源码,会发现没有其他地方引用ngx_http_empty_gif_module,
那这个module是怎么注册并应用起来的呢?
如果熟悉 Apache的代码,会发现这和 Apache 2.0的module机制非常类似——每个module都对应到一个module主结构变量,通过这个主结构变量可以访问到这个module的其他内容,该modu