Nginx模組開發(1) 初探模組開發流程

2021-07-09 13:19:36 字數 3892 閱讀 8451

一、準備工作

1、安裝pcre庫

cd /usr/local/

wget

tar -zxvf pcre-8.38.tar.gz

cd pcre-8.38

./configure

make

make install

2.安裝zlib

cd /usr/local/

wget

tar -zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make

make install

3、安裝ssl

cd /usr/local/

wget

tar -zxvf openssl-1.0.1c.tar.gz

cd openssl-1.0.1c

./config

make

make install

在安裝時如果出現如下錯誤:pod document had syntax errors at /usr/bin/pod2man line 69. make .那麼,解決如下:

rm /usr/bin/pod2man

4.安裝nginx

cd /usr/local

wget

tar -zxvf nginx-1.2.8.tar.gz

在此先不安裝nginx,後面跟模組一起安裝。

二、配置,編寫模組

1、目錄結構說明

2、編寫config

vi config

複製下面到config中

3、編寫ngx_http_hello_world_module.c

複製下面**到ngx_http_hello_world_module.c中

4、修改nginx配置檔案

vi /usr/local/nginx-1.6.0/conf/nginx.conf

在server那裡新增location /hello_world

}}三、編譯模組

--with-pcre=/usr/local/pcre-8.38 --with-zlib=/usr/local/zlib-1.2.7

(假如已經安裝了pcre,zlib在上面可以不帶上--with-pcre,--with-zlib
make
make install
四、測試
1、啟動nginx
/usr/local/nginx/sbin/nginx
2、測試
在瀏覽器中輸入http://localhost/hello_world或者伺服器名/hello_world
你應該會看到:

hello_world, nginx
五、一些問題說明
1、假如已經啟動了nginx,那麼會出現404,not found,這時應該先停止nginx,再開啟
(我在剛開始學的時候總是有這問題,這樣搞以後就沒問題了。。。),reload伺服器不能解決這問題。

Nginx模組開發 研究1

不同的模組流程不同這是乙個直接從從配置中讀取資訊,並返回給客戶端的例子。include include include static char ngx echo readconf ngx conf t cf,ngx command t cmd,void conf static void ngx ec...

nginx的模組開發

nginx剛剛在國內開始流行的時候,我就把它引入公司技術體系,用來替代apache主要做動靜分離。nginx的併發處理能力和穩定性,以及優秀的軟體架構深深得吸引了我,讓我跨入了高效能伺服器開發的大門。正巧當時要基於flash技術開發一套 系統,而且要支援 環境,而當時並沒有什麼好的辦法讓flash通...

Nginx 模組開發 Hello World

最近在研究如何利用 nginx 實現高效能閘道器,這裡記錄一下開發 nginx 擴充套件模組 hello world。wget tar zvxf nginx 1.13.10.tar.gz cd nginx 1.13.10編譯,安裝 nginx 到指定目錄 configure prefix home ...