nginx增加第三方模块
增加第三方模块
============================================================
一、概述
nginx文件非常小但是性能非常的高效,这方面完胜apache。
nginx文件小的一个原因之一是nginx自带的功能相对较少,好在nginx允许第三方模块,第三方模块使得
nginx越发的强大。
nginx已支持动态加载模块
二、安装第三方模块
./configure --prefix=源安装目录 --add-module=/第三方模块解压目录
以安装ngx_cache_purge模块实例
场景一: 在未安装nginx的情况下安装nginx第三方模块
# ./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--add-module=/nginx_module/ngx_cache_purge \
--add-module=/nginx_module/echo-nginx-module-0.58
# make
# make install
# /usr/local/nginx/sbin/nginx
场景二:在已安装nginx情况下安装nginx模块
# /usr/local/nginx/sbin/nginx -V
# ./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--add-module=/nginx_module/ngx_cache_purge
# make
# cp objs/nginx /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -s reload
注意:
安装nginx安装第三方模块实际上是使用–add-module重新编译nginx二进制文件,不要make
install 而是直接把编译目录下objs/nginx 文件直接覆盖老的 nginx文件
============================================================
例如:工作中我们还有这样的需求,配置的nginx文件需要测试结果时,如果能够打印出相应结果的话,就更有利于我们排错了。其实在nginx有个第三方的模可以实现此功能,现在我们来做下配置
(1)查看我们nginx 安装的模块
[root@localhost ~]# /opt/data/nginx/sbin/nginx -V nginx version: nginx/1.17.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
(2)下载模块
[root@localhost ~]# wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz --2019-07-26 22:15:47-- https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
[root@localhost ~]# tar xf v0.60.tar.gz
(3)安装模块
到nginx安装的解压文件中
[root@localhost nginx-1.17.0]# ./configure --prefix=/opt/data/nginx
--with-http_stub_status_module
--with-http_ssl_module
--with-stream
--add-module=/root/echo-nginx-module-0.60
[root@localhost nginx-1.17.0]# make
注意:不能 make install
(4)将生成的nginx新文件将旧文件覆盖
[root@localhost nginx-1.17.0]# systemctl stop nginx [root@localhost nginx-1.17.0]# cp objs/nginx /opt/data/nginx/sbin/nginx [root@localhost nginx-1.17.0]# systemctl start nginx [root@localhost nginx-1.17.0]# nginx -V nginx version: nginx/1.17.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --add-module=/root/echo-nginx-module-0.61
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现