01_自己在开发nginx的坑

1.同目录下文件无法识别

nginx的源码中configure后,会在objs路径下生成一个MakeFile文件,作为noob的我为了可以再扩展模块中添加自定义的C文件,目前只能在自己自定义的ngx_http_helloworld_module.c文件中使用

#include <cJSON.h>
#include <cJSON.c>

如上方式解决无法引用文件函数的问题。

2.编译添加库

同样也是修改objs\Makefile

3.使用g++进行编译

MakeFile中,其他文件依旧使用cc进行编译,自定义的C++文件使用g++进行编译、

3.1 修改一:MakeFiLe

CC =	cc
CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -lm
CPP =	cc -E
#LINK =	$(CC)

#下列内容为新增
CXX = g++
CXXFLAGS = -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -lm
LINK = $(CXX)

3.2 修改二:链接部分进行修改

Makefile中,找到自定义模块对应的链接部分,使用g++进行链接

objs/addon/src/ngx_http_helloworld_module.o:	$(ADDON_DEPS) \
	/home/tianyiyi/nginx/nginx-1.19.6/extends/ngx_http_helloworld_module/src/ngx_http_helloworld_module.c
	#$(CC) -c $(CFLAGS)  $(ALL_INCS) |
	$(CXX) -c $(CXXFLAGS) $(ALL_INCS)
		-o objs/addon/src/ngx_http_helloworld_module.o \
		/home/tianyiyi/nginx/nginx-1.19.6/extends/ngx_http_helloworld_module/src/ngx_http_helloworld_module.c

3.3 修改三:添加extern C

在自定义模块的文件中,如果引用nginx的相关文件,需要使用extern C

extern C{
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_config.h>
}

4. 开启主线程和前台运行模式

nginx.conf中做如下配置

#前台运行
daemon off;

#master处理请求,不会fork出子进程
master_process off

5. 在已经编译好的Nginx中追加模块

5.1 先知晓Nginx当前配置

[root@tianyiyi ngx_TAP]# /usr/local/nginx_TAP/sbin/nginx -V
nginx version: nginx/1.19.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --with-http_auth_request_module --prefix=/usr/local/nginx_TAP --add-module=/home/tianyiyi/nginx/ngx_TAP/extends/ngx_http_access_control_module

5.2 在原先基础上增加要添加的module

此处追加http_auth_request_module模块
Nginxsrc目录中执行

./configure --with-http_auth_request_module --prefix=/usr/local/nginx_TAP  --add-module=/home/tianyiyi/nginx/ngx_TAP/extends/ngx_http_access_control_module

接着 make 即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fantongl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值