Nginx學習記錄-2 hello word 模塊

參考: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中設置

相關文章
相關標籤/搜索