参考:html
http://blog.csdn.net/xiajun07061225/article/details/9130237 nginx
http://tengine.taobao.org/book/chapter_03.html#hello-handlershell
新建模块源码存放的目录浏览器
/home/fan/nginx测试
1)ngx_http_hello_module.c文件的编写spa
2)config文件的编写,用于通知Nginx如何编译本模块。它实际上是一个可执行的Shell脚本。.net
ngx_addon_name=ngx_http_hello_module HTTP_MODULES="$HTTP_MODULES ngx_http_hello_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_hello_module.c"
1. ngx_addon_name:仅在configure执行时使用,设置为模块名。code
2. HTTP_MODULES:保存全部的HTTP模块名称。htm
3. NGX_ADDON_SRCS:指定新增模块的源代码。$ngx_addon_dir等价于/home/fan/nginx,是configure执行时--add-module=PATH的PATH参数。blog
修改配置文件
先修改配置文件再进行编译安装
1)/usr/local/nginx/conf/nginx.conf
编译安装
1)
./configure --prefix=/usr/local/nginx --add-module=/home/fan/nginx --conf-path=/usr/local/nginx/nginx.conf
/usr/local/nginx:Nginx安装部署后的根目录
/home/fan/nginx:ngx_http_hello_module.c和config文件所在的文件夹。
/usr/local/nginx/nginx.conf:配置文件放置路径
2)sudo make
3)sudo make install
测试
1)终端下输入命令 lynx http://127.0.0.1/test 或直接在浏览器中输入地址 http://127.0.0.1/test
2)Lynx:纯文本网页浏览器
3)127.0.0.1:回送地址,指本地机,通常用来测试。
4)/test 在配置文件nginx.conf中设置