Nginx 動態添加模塊

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

1.下載並安裝nginx

詳情請看:blog.csdn.net/dushiwodecu…linux

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:github.com/openresty/e…
    當前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.測試訪問瀏覽器

相關文章
相關標籤/搜索