1. 程式人生 > >Nginx自定義擴充套件模組及編譯

Nginx自定義擴充套件模組及編譯

1. 概述

2. 擴充套件模組(假設根目錄名稱為nginx)

  • nginx/configure檔案中可以修改配置檔案路徑:
    • 例如像把配置檔案從預設的nginx.conf改為webserver.conf:NGX_PREFIX=${NGX_PREFIX:-/usr/local/nginx}改為NGX_PREFIX=${NGX_PREFIX:-/xxx/xxx/xxx}
  • nginx/src/core/ngx_conf.c中的ngx_conf_full_name是配置檔名的配置?
  • nginx/src/core/ngx_log.c中是日誌的配置?
  • 處理流程
    • 各個模組中會以固定格式,定義一些結構體,ngx_http_core_loc_conf_t* clcf;並設定一個clcf->handler
    • 先根據nginx/auto/modules中註冊的模組,到(ngx_http_apptest_handler、xngx_recom_handler、ngx_recom_handler方法?怎麼判斷轉發到哪一個模組?
    • 然後每個模組都初始化一個自定義的Entry類(相當於Web api中的路由轉發設定,只是自行進行了解析url和轉發呼叫各個處理函式),用於做路由轉發(根據url呼叫不同的邏輯處理類)

3. 專案學習

  • 為什麼把名稱中的nginx改為了webserver?因為用了BSD協議,隨便改??
    • 為什麼把預設引用的<nginx.h>都改成了#include "../../core/webserver.h"?當然也就同時要修改使用的地方如nginx/auto/sources
      • nginx/src/core/ngx_module.h
      • nginx/src/stream/ngx_stream_variables.c
      • nginx/src/os/unix/ngx_posix_init.c
      • nginx/src/http/v2/ngx_http_v2_filter_module.c
      • nginx/src/http/ngx_http_header_filter_module.c
      • nginx/src/http/ngx_http_special_response.c
    • 為什麼把Copyright中的Nginx都改成了webserver?
      • nginx/auto/cc/conf等
    • 為什麼把core下面nginx改成了webserver?
  • 定製修改的檔案(動了邏輯的)
    • nginx/conf(修改配置檔案位置)
    • nginx/auto/cc/gcc
    • nginx/auto/conf + nginx/auto/lib/app/conf(前者引用後者)
    • nginx/auto/install(調整安裝過程,如拷貝一些配置檔案到指定位置)
    • nginx/auto/make(編譯相關,如g++)
    • nginx/auto/modules(註冊自定義及使用到的擴充套件模組)
    • nginx/auto/options(一些nginx開關,如是否開啟代理、重寫等)
    • nginx/src/core/ngx_log.c
    • nginx/src/core/ngx_conf.c
    • nginx/src/core/nginx.c重新命名為nginx/src/core/webserver.c,並沒有修改邏輯?