随笔 - 224  文章 - 41  trackbacks - 0
<2013年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

享受编程

常用链接

留言簿(11)

随笔分类(159)

随笔档案(224)

文章分类(2)

文章档案(4)

经典c++博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

nginx.org上,下载对应的nginx

测试nginx是否可以安装

./configure

如果出现

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.


执行:

sudo aptitude install libpcre3-dev

如果还缺少其他包,继续安装。直到./configure没有错误

sudo make

sudo make install

启动nginxsudo /usr/local/nginx/sbin/nginx

另外启动一个命名窗口:


安装curl

sudo apt-get install curl

执行curl -i http://localhost

或者用浏览器访问http://localhost/

就可以看到welcome to nginx的欢迎字幕 表示安装成功



加载Empty Gif插件


http://www.evanmiller.org/网站中

有篇文章http://www.evanmiller.org/nginx-modules-guide.html介绍了nginx的开发,比较全面,但较老,如果要详细了解nginx的模块开发,还得熟悉nginx的源代码。

Empty Gif 较为简单,主要的功能就是浏览器访问某个地址,返回一个gif图片。


如何编译:

Empty Gif使用到了图片库,先安装

sudo apt-get install libmagickwand-dev 

下载Empty Gif代码

安装nginx模块的一般步骤如下:

1、编写模块config文件,这个文件需要放在和模块源代码文件放在同一目录下。文件内容如下: 

ngx_addon_name=模块完整名称 

HTTP_MODULES="$HTTP_MODULES 模块完整名称" 

NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/源代码文件名" 

编写源代码文件,放在同一个目录下


2、
进入Nginx源代码,使用命令编译安装


   
./configure --prefix=安装目录 --add-module=模块源代码文件目录 --with-debug

make 

sudo make install 


3、
修改nginx的配置文件


location /circles {

        circle_gif;

    }



4、启动nginx

sudo  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 


在浏览器中输入

http://localhost/circles/ffffff/000000/20.gif 

就可以看到





其中url的格式如下:

/circles/ffffff/000000/20.gif

/circles/<background color>/<foreground color>/<size>.gif


模块是如何注册

nginx代码的auto目录中,有一个名为sources的文件,根据编译选项(configure的参数)的不同,m4宏变量HTTP_MODULES的值会发生变化:

如果指定了使用empty gif模块(默认就是使用了),则最终m4宏变量HTTP_MODULES的值可能如下:

HTTP_MODULES="ngx_http_module /

              ngx_http_core_module /
              ngx_http_log_module /
              ngx_http_upstream_module /
              ngx_http_empty_gif_module "

注意:这里的ngx_http_empty_gif_module字符串对应了ngx_http_empty_gif_module.c文件中的Module主结构变量名。 


参考文章:

http://www.evanmiller.org/ 

http://www.evanmiller.org/nginx-modules-guide.html 

http://www.162cm.com/p/ngx_ext.html 

http://www.codinglabs.org/html/intro-of-nginx-module-development.html 

http://blog.csdn.net/conezxy/article/details/1869130 
http://ri0day.blogbus.com/logs/61820056.html

http://wiki.nginx.org/3rdPartyModules 中有很多关于第三方模块的开发,国人agentzh在这方面做了大量的工作。




posted on 2012-01-05 15:12 漂漂 阅读(2446) 评论(0)  编辑 收藏 引用 所属分类: c++经典文章转载

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理