千家信息网

Nginx如何编译连接

发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,这篇文章将为大家详细讲解有关Nginx如何编译连接,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。nginx 组织过程/auto/configure(获取config
千家信息网最后更新 2025年02月07日Nginx如何编译连接

这篇文章将为大家详细讲解有关Nginx如何编译连接,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

nginx 组织过程

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

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

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

针对http geo模块连接过程进行示范

1.configure

path:auto/configure

. auto/options...

2.options 参数

  • path: auto/option

  • path: auto/modules

某个配置是否开启

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

HTTP_GEO变量被设置为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 声明目标模块(geo, 自定义模块)

  • ngx_modules: 注册模块

  • ngx_module_names: 定义模块名

4.objs/Makefile

  • 编译目标.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中已经连接了目标模块

  • ngx_http_geo_module

  • ngx_http_mytest_module(自定义模块)

➜  nginx git:(hyh_test) ✗ nm objs/nginx | grep geo_mod00000001000a5420 D _ngx_http_geo_module00000001000bdf68 b _ngx_http_geo_module_ctx➜  nginx git:(hyh_test) ✗ ➜  nginx git:(hyh_test) ✗ nm objs/nginx | grep mytest 0000000100071860 t _ngx_http_mytest_block00000001000a5500 d _ngx_http_mytest_commands00000001000a5570 D _ngx_http_mytest_module00000001000bdfb8 b _ngx_http_mytest_module_ctx➜  nginx git:(hyh_test) ✗

关于"Nginx如何编译连接"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

0