Ubuntu20.04 nginx 编译、配置错误处理

具体安装教程点这里

配置过程参考了这篇文章

下面主要记录在执行 ./configure 中所遇到的错误。

 第一个问题:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

 执行下列安装此问题解决。

sudo apt-get install libpcre3 libpcre3-dev

第二个问题:

继续报错

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib 
### 如何在Ubuntu 20.04安装配置Nginx插件 #### 安装必要的依赖项 为了确保能够顺利编译并安装 Nginx 插件,需要先安装一些基础工具和库文件。这包括 GCC 编译器以及构建必需的基础包: ```bash sudo apt-get update sudo apt-get install -y gcc build-essential ``` 这些命令会更新本地软件源列表,并安装所需的开发环境组件[^3]。 #### 下载并准备Nginx源码 如果打算通过源码来添加模块,则需下载官方发布的稳定版 Nginx 源代码包。可以从官方网站获取最新版本的 tarball 文件,之后解压该存档: ```bash cd /usr/src sudo wget http://nginx.org/download/nginx-1.18.0.tar.gz sudo tar zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0/ ``` 此过程将创建一个新的目录 `nginx-1.18.0` 并进入其中。 #### 添加第三方模块支持 对于想要集成进来的特定插件或模块(比如 HTTP upstream check module),通常有两种方法实现: - **动态加载**: 不改变现有服务的情况下增加新特性; - **静态链接**: 将额外的功能直接嵌入到可执行程序内。 这里以动态加载为例说明操作流程。假设要加入一个名为 `ngx_http_upstream_check_module` 的健康检查模块, 可按照如下步骤进行: 1. 获取目标模块源码; 2. 使用 `--add-dynamic-module=PATH_TO_MODULE_SOURCE` 参数重新编译 Nginx; 具体做法如下所示: ```bash # 假设已经克隆了 git@github.com:yaoweibin/nginx_upstream_check_module.git 到当前路径下 ./configure --with-compat --add-dynamic-module=./nginx_upstream_check_module make modules sudo cp objs/ngx_http_upstream_check_module.so /etc/nginx/modules/ ``` 上述指令中的 `--with-compat` 是为了让旧版本兼容新增加的动态模块;而 `objs/ngx_http_upstream_check_module.so` 即为生成的目标共享对象文件。 #### 修改Nginx配置启用模块 编辑 `/etc/nginx/nginx.conf` 或者其他站点级别的 `.conf` 文件,在适当位置引入刚才复制过去的 .so 文件,并定义相应的语法结构。例如: ```nginx load_module modules/ngx_http_upstream_check_module.so; upstream backend { server 192.168.1.100 weight=5 max_fails=2 fail_timeout=30s; server 192.168.1.101 backup; check interval=3000 rise=2 fall=5 timeout=1000 type=http; } ``` 这段配置实现了对上游服务器组 "backend" 中成员的状态监测功能。 #### 测试与重启服务 完成以上更改后,记得验证配置的有效性再尝试启动或重载 Nginx 服务: ```bash sudo nginx -t sudo systemctl restart nginx ``` 这样就完成了基于 Ubuntu 20.04 LTS 系统环境下向 Nginx 动态添加自定义模块的过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值