温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx如何编译连接

发布时间:2021-12-08 11:48:22 来源:亿速云 阅读:123 作者:小新 栏目:云计算

这篇文章将为大家详细讲解有关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_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) ✗

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI