Nginx 動態添加模塊

Nginx 動態添加模塊

nginx模塊依賴:nginx的一些模塊需要第三方支持,例如gzip模塊需要zlib庫,rewrite模塊需要pcre庫,ssl功能需要openssl庫。
根據需求添加不同模塊
例添加echo模塊:

1.下載並安裝nginx

詳情請看:http://blog.csdn.net/dushiwodecuo/article/details/78393454

2.查看nginx已安裝的模塊

/usr/local/nginx/sbin/nginx -V
  • 舊版本模塊
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

3.選擇與nginx版本所符合的模塊版本

echo:https://github.com/openresty/echo-nginx-module/tags
當前nginx版本爲:1.12.2,選擇echo版本爲0.61

4.下載模塊

wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz

5.解壓模塊

tar -zxvf v0.61.tar.gz -C /usr/local/nginxgz

6.爲nginx添加模塊

6.1.切換到nginx的源碼目錄(即解壓後的目錄)

cd /usr/local/nginxgz/nginx-1.12.2

6.2.添加新模塊

./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginxgz/echo-nginx-module-0.61 --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

7.重新編譯

make
make install

8.測試

  • Linux上的測試

8.1.修改配置文件

8.1.1.修改nginx.conf,添加測試域名模塊

server{
        server_name echo.chen.com;
        listen 80;
        location /{
                echo "it is echo module...";
        }
   }

8.1.2.修改Linux host文件

echo '192.168.1.111 echo.chen.com' >> /etc/hosts

8.2.重啓nginx

/usr/local/nginx/sbin/nginx -s reload
  • 注:若是重啓nginx之後還沒能訪問到,直接reboot,重啓虛擬機等即可

8.3.訪問測試


  • Windows上瀏覽器測試

8.1.修改配置文件

8.1.1.修改nginx.conf,添加測試域名模塊

server{
        server_name echo.chen.com;
        listen 80;
        location /{
                default_type 'text/html';  
                echo "it is echo module...";
        }
   }
  • 注: 如果沒有這個default_type,瀏覽器訪問則會一直下載文件而不是輸出在瀏覽器上

8.1.2.修改Windows host文件

192.168.1.111 echo.chen.com

8.2.重啓nginx

/usr/local/nginx/sbin/nginx -s reload
  • 注:若是重啓nginx之後還沒能訪問到,直接reboot,重啓虛擬機等即可

8.3.測試訪問瀏覽器

發佈了51 篇原創文章 · 獲贊 30 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章