溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Nginx如何編譯連接

發(fā)布時間:2021-12-08 11:48:22 來源:億速云 閱讀:132 作者:小新 欄目:云計算

這篇文章將為大家詳細(xì)講解有關(guān)Nginx如何編譯連接,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

nginx 組織過程

  • /auto/configure(獲取configure的配置,生成Makefile)

  • objs/Makefile(由第一步生成)

  • make(*.o生成,連接成nginx)

針對http geo模塊連接過程進(jìn)行示范

1.configure

path:auto/configure

. auto/options
...

2.options 參數(shù)

  • path: auto/option

  • path: auto/modules

某個配置是否開啟

 --without-stream_geo_module        disable ngx_stream_geo_module
  --with-debug                       enable debug logging

HTTP_GEO變量被設(shè)置為YES, geo模塊開啟.

    if [ $HTTP_GEO = YES ]; then
        have=NGX_HTTP_X_FORWARDED_FOR . auto/have

        ngx_module_name=ngx_http_geo_module
        ngx_module_incs=
        ngx_module_deps=
        ngx_module_srcs=src/http/modules/ngx_http_geo_module.c
        ngx_module_libs=
        ngx_module_link=$HTTP_GEO

        . auto/module
    fi

3.objs/ngx_modules.c

  • extern 聲明目標(biāo)模塊(geo, 自定義模塊)

  • ngx_modules: 注冊模塊

  • ngx_module_names: 定義模塊名

4.objs/Makefile

  • 編譯目標(biāo).o

  • 把目標(biāo).o連接到nginx

eg:ngx_http_geo_module.o模塊的生成

objs/src/http/modules/ngx_http_geo_module.o:	$(CORE_DEPS) $(HTTP_DEPS) \
	src/http/modules/ngx_http_geo_module.c
	$(CC) -c $(CFLAGS) $(CORE_INCS) $(HTTP_INCS) \
		-o objs/src/http/modules/ngx_http_geo_module.o \
		src/http/modules/ngx_http_geo_module.c

5.驗證nginx中已經(jīng)連接了目標(biāo)模塊

  • ngx_http_geo_module

  • ngx_http_mytest_module(自定義模塊)

?  nginx git:(hyh_test) ? nm objs/nginx | grep geo_mod
00000001000a5420 D _ngx_http_geo_module
00000001000bdf68 b _ngx_http_geo_module_ctx
?  nginx git:(hyh_test) ? 
?  nginx git:(hyh_test) ? nm objs/nginx | grep mytest 
0000000100071860 t _ngx_http_mytest_block
00000001000a5500 d _ngx_http_mytest_commands
00000001000a5570 D _ngx_http_mytest_module
00000001000bdfb8 b _ngx_http_mytest_module_ctx
?  nginx git:(hyh_test) ?

關(guān)于“Nginx如何編譯連接”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI