搜尋
首頁後端開發php教程nginx HTTP模組組成

原文連結:http://cjhust.blog.163.com/blog/static/17582715720124544047608/

115 ngx_conf_s

struct ngx_conf_s {

    char            ngx_array_t          *args;             //

 

    ngx_cycle_t         參數    ngx_pool_t           

ngx_pool_t           *temp_pool;

    文件資訊 「./conf/main.conf」

              / /日誌

 *  ctx;                    //(void ****)cycle->conf_ctx,而裝的是所有模組的設定資訊

    ngx_uint_t            的模組的型別    ngx_uint_t          指令的類型

     ng

    char               上面的handler使用};

備};備};

ngx_conf_s

起著橋樑的作用。 ngx_http_conf_ctx_t

typedefstruction

    void        **main_conf;

       void        **loc_conf;

} ngx_http_conf_ctx_t; HTTP 區塊

中的設定結構主要分為3

中,main ngx_http_module_t (*預先設定)(ngx_conf_ t *cf);    ngx_int_t   (*設定後)(ngx_conf_t * cf); 

  

    char       *( *init_main_conf)(ngx_conf_t *cf, void * conf);

 

    void     

    char       *(*merge_srv _conf)(ngx_conf_t *cf, void *prev, void *conf);

 

    void         char       *(*merge_loc_conf) )(ngx_conf_t *cf, void *prev, void *conf);

} ngx_http_module_t;

備註: 主要有上面

8個函數組成。

ngx_command_s

struct x_command_s

struct x_command_s      名詞;

    ngx_uint_t              *(*set)(ngx_conf_t *cf, ngx_command_t * cmd, void *conf);

    ngx_uint_t            偏移;

    void                 *post;

}; x_null_command  { ngx_null_string, 0, NULL, 0, 0, 空}

2HTTP ctx

2.1 create_main_conf(ngx_conf_t *cf)

,cf. 回傳值: void *

備註:_Yommo_cf

gx_http _get_module_ main _conf的結果;範例:oid_cf. {

  ngx_http_barrier_conf_t  *conf;   / /自訂的一個結構

  conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_barrier_conf_t)); {

    return NULL;

  } 

  conf->enable = NGX_CONF_UNSET;

  return conf;                                         //

返回自定義的結構

}

2.2 create_srv_conf(ngx_conf_t *cf)

_參數

回傳值:

void *

備註:回傳值可以作為ngx_http_conf_get_get_y_hkq; _get_module_ srv_conf的結果;

範例:oid_cf. {

  ngx_http_barrier_conf_t  *conf;   // 自訂的一個結構  conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_barrier_conf_t)); return NULL;  }

   conf->enable = NGX_CONF_UNupturn;                                 ///已回復

}

2.3 create_loc_conf(ngx_conf_t *cf)

參數:

回傳值:

void *

備註:

回傳值可以作為

ngx_http_conf_get_smm_Lot; _get_module_loc_conf

的結果;

範例:

_cf;

{

  ngx_http_barrier_conf_t  *conf;   // 自訂的一個結構

  conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_barrier_conf_t));  //init by pcalloc

  }

  conf->enable = NGX_CONF_UNSET            //

回傳自訂的結構

}_cf 參數:

ngx_conf_t *cf

,配置結構體;

備註:回傳值只是作為操作是否正確的判斷;

範例:_pstatic ngx_conf_t *cf){

    ngx_http_variable_t  *var, *v; 

          var = ngx_http_add_variable(cf, &v->name, v- >flags);

        if (var == NULL) {

        }

 

        var->get_handler = v->get_handler;

var->數據 = v->data;

    }

 

  2.5 init_main_conf(ngx_conf_t *cf, void *conf)

參數:

ngx_conf_t main

時的回傳值,在這裡作為參數;

回傳值:

char *

NGX_CONFOK

NGX_CONFOK

備註:

回傳值只是作為操作是否正確的一個判斷;

範例:static char *🎎 {    ngx_http_core_main_conf_t *cmcf = conf;//create_main時是未配置if (cmcf->L_names_hash__hash_        cmcf->server_names_hash_max_size = 512;    //這裡是

init    }  UINT) {        cmcf->server_names_hash_bucket_size = ngx_cacheline_size;

 

    cmcf->server_names_hash_bucket_size =

            ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);

    if (cmcf->variables_h ash_max _size == NGX_CONF_UNSET_UINT) {

       

    }

 

    if (cmcf->variables_hash_bucket_size ====   cmcf->data_hash_bucket_size = 64;

    }

 

_cmb; =

               ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);  if (cmcf ->ncaptures) {

        cmcf->n捕獲= (cmcf->n捕獲+ 1) * 3;

    }

 

  6 merge_srv_conf( ngx_conf_t *cf,無效*prev,無效 *conf)

參數:

ngx_conf_t配置結構體,

conf

伺服器

的配置結構體;

prev=cf->ctx.srv_conf[x_index],c/pan>

,正確的回傳值是

NGX_CONF_OK

備註:備註: static char * ngx_http_barrier_merge_conf(ngx_conf_t *cf, void *parent, void *child){ x_http_barrier_conf _ t *conf = 孩子;   if (conf->shm_zone == NULL){     *conf = *pre   ngx_conf_merge_value( conf-& > 促成、預防-> 促成, 0);  //default is 0

  return NGX_CONF_OK;} 啟用=1

,而

伺服器{}啟用= NGX_CONF_UNSET,則將

伺服器

enable=main

enable=1 loc_conf (ngx_conf_t *cf, void *prev, void *conf)

原理同

merge_srv_conf(ngx_conf_t *cf, void *prev, void *conf)

2.8 postconfiguration(ngx_conf_t *cf)

參數:

回傳值:

ngx_int_t

,正確的回傳值是

NGX_OK

備註:

備: 範例:

static ngx_int_t ngx_http_tracker_init(ngx_conf_t *cf)

{

  

}

備註:

將全域變數

flag 清零,用於判斷是否有barrier模組。如果不清零,將會導致如果配置中沒有加入barrier zone,在kill –HUP時,由於全域變數flag值不變,即不為0,指令出現段錯誤。 3HTTP commands

4、常用變數 00      //

指令存放位置#define NGX_HTTP_SRV_CONF   #define NGX_HTTP_LOC_CONF         0x08000000

#define NGX_HTTP_UPS_CONF X_HTTP_SIF_CONF         0x20000000

#define NGX_HTTP_LIF_CONF    MT_CONF         0x800000000 

#define NGX_HTTP_MAIN_CONF_OFFOFF時期與t, loc_conf)

 

範例:

static ngx_command_command_com [] = {

{

ngx_string("print"),

ng 

      ngx_http_print_setup,       

      //set()

      //set()

,會轉換讀入指令傳進來的參數,並將適當的值存到配置結構體

      NGX_HTTP_LOC_CONF_OFFSET,

      NULL

},

 

      ngx_null_command

};

};

5.1 

處理

Request

Request

ngx_http_get_module_main_conf

函數功能:

根據request

#define ngx_http_get_module_main_conf(r, module)           (r)->main_conf[module.ctx_index]

ngx_http_get_module_srv_conf

函數功能: 配置。 #define ngx_http_get_module_srv_conf(r, module)  (r)->srv_conf[module.ctx_index] 函數功能:

根據

request

請求和模組得到location

配置。 #define ngx_http_get_module_loc_conf(r, module)  (r)->loc_conf[module.ctx_index] 解析conf

ngx_http_conf_get_module_main_conf

函數功能:根據conf

#define ngx_http_conf_get_module_main_conf(cf, module)         _http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]

ngx_http_conf_get_module_srv_conf

函數功能:根據conf結構和模組得到server配置。

#define ngx_http_conf_get_module_srv_conf(cf, module)         (ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]

ngx_http_conf_get_module_loc_confngx_http_conf_get_module_loc_conf

函數功能:根據

conf

結構和模組得到

location

配置。

#define ngx_http_conf_get_module_loc_conf(cf, module)         ((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]5.3 Cycle ngx_http_cycle_get_module_main_conf

#define ngx_http_cycle_get_module_main_confࠠ

    (cycle->conf_ctx[ngx_http_module.index] ?              

        ((ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index ])      

            ->main_conf[Hule.ctx_index                  NULL)

    NULL) 

 

 

以上就介紹了nginx HTTP模組組成,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
高流量網站的PHP性能調整高流量網站的PHP性能調整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依賴注入:初學者的代碼示例PHP中的依賴注入:初學者的代碼示例May 14, 2025 am 12:08 AM

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

PHP性能:是否可以優化應用程序?PHP性能:是否可以優化應用程序?May 14, 2025 am 12:04 AM

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

PHP性能優化:最終指南PHP性能優化:最終指南May 14, 2025 am 12:02 AM

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。