Nginx - 动态模块

Nginx - 动态模块 首页 / Nginx入门教程 / Nginx - 动态模块

Nginx Plus是一种模块化架构。我们可以在软件模块中包含新功能,可以根据需要将其插入正在运行的Nginx Plus实例中。

动态模块包括Nginx Plus的功能,例如通过IP地址对用户进行地理位置定位,调整图像大小以及将脚本嵌入到Nginx Plus事件处理模型中。模块由Nginx,公司和第三方开发人员创建。

显示可用模块列表

要显示可用模块的列表,请运行以下命令(对于Debian或Ubuntu OS):

$ apt-cache search nginx-plus-module

nginx-plus-module-geoip - NGINX Plus, provided by Nginx, Inc. (GeoIP dynamic modules)
nginx-plus-module-geoip-dbg - Debugging symbols for the nginx-plus-module-geoip
nginx-plus-module-geoip2 - NGINX Plus, provided by Nginx, Inc. (3rd-party GeoIP2 dynamic modules)
nginx-plus-module-geoip2-dbg - Debugging symbols for the nginx-plus-module-geoip2
nginx-plus-module-headers-more - NGINX Plus, provided by Nginx, Inc. (3rd-party headers-more dynamic module)
nginx-plus-module-headers-more-dbg - Debugging symbols for the nginx-plus-module-headers-more
nginx-plus-module-image-filter - NGINX Plus, provided by Nginx, Inc. (image filter dynamic module)
nginx-plus-module-image-filter-dbg - Debugging symbols for the nginx-plus-module-image-filter

让我们看一些重要的动态模块的列表:

Brotli

Brotli是一种通用的无损数据压缩算法,它使用了霍夫曼编码,LZ77算法和二阶上下文建模的变体。其压缩率可与当前最好的通用压缩方法相媲美。

安装步骤:

1. 首先,安装Brotli模块。

$ apt-get install nginx-plus-module-brotli

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level(" main")上下文中添加以下指令:

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

Cookie-Flag

Set-Cookie 上游响应标头中为Cookie设置标志 HttpOnly secure SameSite

安装步骤:

1. 安装Cookie-Flag模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-cookie-flag

对于Debian或Ubuntu:

$ apt-get install nginx-plus-module-cookie-flag

对于SLES:

$ zypper install nginx-plus-module-cookie-flag

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level("main")上下文中添加以下指令:

load_module modules/ngx_http_cookie_flag_filter_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

Encrypted-Session

这个动态模块为基于MAC的AES-256的Nginx变量提供了一些加密和解密支持。它通常与Set-Misc动态模块和Nginx重写模块一起使用。

安装步骤:

1.安装加密的会话模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-encrypted-session

对于Debian或Ubuntu:

$ apt-get install nginx-plus-module-encrypted-session

对于SLES:

$ zypper install nginx-plus-module-encrypted-session

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level("main")上下文中添加以下指令:

load_module modules/ndk_http_module.so;
load_module modules/ngx_http_encrypted_session_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

GeoIP

使用预编译的MaxMind GeoIP数据库,基于客户端的IP地址为Http和TCP/UDP流量创建变量:

安装步骤:

1.安装GeoIP模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-geoip

对于Debian或Ubuntu:

$ apt-get install nginx-plus-module-geoip

对于SLES:

$ zypper install nginx-plus-module-geoip

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level("main")上下文中添加以下指令:

load_module modules/ngx_http_geoip_module.so;
load_module modules/ngx_stream_geoip_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

GeoIP2

使用预编译的MaxMind GeoIP2数据库,基于客户端的IP地址创建变量,该数据库提供原始GeoIP数据库中不存在的本地化名称信息。

安装步骤:

1.安装GeoIP2模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-geoip2

对于Debian或Ubuntu:

$ apt-get install nginx-plus-module-geoip2

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level("main")上下文中添加以下指令:

load_module modules/ngx_http_geoip2_module.so;
load_module modules/ngx_stream_geoip2_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

Headers-More

它用于设置和清除输入和输出标头,以扩展核心标头模块:

安装步骤:

1. 安装Headers-More模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-headers-more

对于Debian或Ubuntu:

$ apt-get install nginx-plus-module-headers-more

对于SLES:

$ zypper install nginx-plus-module-headers-more

2.在Nginx Plus主配置文件/etc/nginx/nginx.conf的 level(" main")上下文中添加以下指令:

load_module modules/ngx_http_headers_more_filter_module.so;

3.根据模块要求执行一些其他配置。

4.要启用该模块,请重新加载Nginx Plus:

$ nginx -t && nginx -s reload

Image-Filter

裁剪(Crop),旋转(rotate),调整大小(resize)并执行GIF,JPEG和PNG图像的其他转换。

安装步骤:

1. 安装Image-Filter模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-image-filter

对于Debian和Ubuntu:

$ apt-get install nginx-plus-module-image-filter

对于SLES:

$ zypper install nginx-plus-module-image-filter

2.在主NGINX Plus配置文件/etc/nginx/nginx.conf的 level(" main")上下文中添加以下指令:

load_module modules/ngx_http_image_filter_module.so;

3.根据模块要求执行其他配置。

4.要启用该模块,请重新加载NGINX Plus:

$ nginx -t && nginx -s reload

Lua

将Lua协同例程集成到Nginx的事件处理模块中。

安装步骤:

1. 安装模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-lua

对于Debian和Ubuntu:

$ apt-get install nginx-plus-module-lua

对于SLES:

$ zypper install nginx-plus-module-lua

2.在NGINX Plus主配置文件/etc/nginx/nginx.conf的 level("main")上下文中添加以下两个指令:

load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;

Note: 指令必须按上述顺序。

3.根据模块要求执行其他配置。

4.重新加载NGINX Plus以启用该模块:

$ nginx -t && nginx -s reload

Perl

在Perl中实现位置和变量处理程序,并将Perl调用插入SSI(服务器端包含)。

安装步骤:

1.安装Perl模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-perl

对于Debian/Ubuntu:

$ apt-get install nginx-plus-module-perl

对于SLES:

$ zypper install nginx-plus-module-perl

2.在主NGINX Plus配置文件/etc/nginx/nginx.conf的 level(" main")上下文中添加以下指令:

load_module modules/ngx_http_perl_module.so;

3.根据模块要求执行其他配置。

4.要使模块重新加载NGINX Plus:

$ nginx -t && nginx -s reload

RTMP

流RTMP(实时消息协议),Apple HTTP实时流(HLS)和基于HTTP的动态自适应流(DASH)视频格式。

安装步骤:

1.安装RTMP媒体流模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-rtmp

对于Debian和Ubuntu:

$ apt-get install nginx-plus-module-rtmp

对于SLES:

$ zypper install nginx-plus-module-rtmp

2.在主NGINX Plus配置文件/etc/nginx/nginx.conf的顶级(" main")上下文中添加以下指令:

load_module modules/ngx_rtmp_module.so;

3.根据模块要求执行其他配置。

4.要启用该模块,请重新加载NGINX Plus:

$ nginx -t && nginx -s reload

Set-Misc

通过扩展Nginx核心重写模块,实现大量其他set_ *指令。

安装步骤:

1. 安装Set-Misc模块。

对于CentOS,Amazon Linux,Oracle Linux和RHEL:

链接:https://www.learnfk.comhttps://www.learnfk.com/nginx/nginx-dynamic-modules.html

来源:LearnFk无涯教程网

$ yum install nginx-plus-module-set-misc

对于Debian和Ubuntu:

$ apt-get install nginx-plus-module-set-misc

对于SLES:

$ XXXipper install nginx-plus-module-set-misc

2.在NGINX Plus主配置文件/etc/nginx/nginx.conf的 level(" main")上下文中添加以下两个指令:

load_module modules/ndk_http_module.so;
load_module modules/ngx_http_set_misc_module.so;

Note: The directives must be in this order.

3.根据模块要求执行其他配置。

4.重新加载NGINX Plus以启用该模块:

$ nginx -t && nginx -s reload

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

Swift核心技术与实战 -〔张杰〕

RPC实战与核心原理 -〔何小锋〕

Flink核心技术与实战 -〔张利兵〕

容器实战高手课 -〔李程远〕

React Hooks 核心原理与实战 -〔王沛〕

如何落地业务建模 -〔徐昊〕

Vue 3 企业级项目实战课 -〔杨文坚〕

工程师个人发展指南 -〔李云〕

好记忆不如烂笔头。留下您的足迹吧 :)