添加第三方模块
https://www.cnblogs.com/anttech/p/10687163.html
由于 Nginx 不能动态加载大多数第三方模块,通常需要在编译时加入
场景1:在未安装 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
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
场景2:在已安装 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不需要执行make install)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
nginx -V 查看 nginx 编译时启用的模块,输出中 --with-(内置) 和 --add-module(第三方) 参数后面列出的就是已启用的模块
常见内置模块
- http_core_module:HTTP 服务的核心功能模块
- http_ssl_module:支持 HTTPS(SSL/TLS)
- http_proxy_module:实现反向代理功能
- http_rewrite_module:用于 URI 重写和跳转规则
- http_gzip_module:支持 Gzip 压缩,优化传输效率
- http_upstream_module:配置后端服务器组和负载均衡
- http_static_module:直接提供静态文件服务
- http_limit_conn_module:限制客户端的并发连接数
- http_limit_req_module:限制客户端的请求速率
- http_stub_status_module:提供实时监控页面
常见第三方模块
- ngx_http_brotli_module:支持 Brotli 压缩,提高静态资源压缩率
- ngx_http_headers_more_module:灵活设置或修改 HTTP 请求和响应头
- ngx_http_auth_ldap_module:支持基于 LDAP 的身份认证
- nginx-vts-module:提供详细的状态统计和图形化展示
- ngx_http_image_filter_module:动态调整图片大小和格式