Nginx模块综合简介
Nginx模块介绍
对于Nginx来说,可能每个人都并不默认。多多少少都使用过,或者说是听说过。Nginx凭借其高并发、低消耗、热部署等特点,逐渐成为WEB服务器软件的首选。可以算作为Apache之后的新贵。

Nginx一般常被用作:基于http或者https协议的web服务器软件,反向代理软件,负载均衡软件等等。这都有赖于它本身提供的一些模块的机制。所以,整个Nginx就是一个模块化的软件。需要什么功能,就调用其对应的模块,并配置其语法即可。
当然了,在某些情况下,一些业务需求。在官方模块中没有实现,也可以通过扩展第三方模块的方式来实现它们。Nginx在这方面,可谓方便至极。
接下来,就一起来了解一下常用的官方模块和第三方模块。
Nginx官方模块
1、官方模块的概述
打开官方文档中,可以看到Nginx的语法和模块被分为四块。
第一块

第二块 http这一部分的模块,都是基于http的功能和操作

第三块 邮箱代理模块

第四块 stream模块 基于tcp协议的一些模块

根据实际实现需求,查找对应的模块及其语法。方便快速实现功能。
一般常见于使用http相关的模块。
常见使用的官方模块
2.1、ngx_http_core_module
提供http协议的支持。平常配置的http段、server虚拟主机段、location段等。都是此模块的中的一些配置语法。
2.2、ngx_http_gzip_module
使用‘gzip’方法压缩,有助于将传输数据的大小减少为一半甚至更多。提供请求返回速度。
2.3、ngx_http_proxy_module
该模块允许将请求转发到其他服务器,实现代理服务器的功能。
常见于实现反向代理服务器。
2.4、ngx_http_rewrite_module
该模块用于使用pcre正则表达式更改请求的URI,返回重定向,或者判断选择对应的配置项。
2.5、ngx_http_upstream_module
该模块用户分发到不同的服务器节点。支持由proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, memcached_pass, grpc_pass等的服务器组。
Nginx第三方模块
在某些特定业务场景下,官方模块没有实现的功能,或者不满足使用需求。就可以借助一些开发者发布的第三方模块,扩展Nginx的功能,使其更为强大。满足业务需求。
官方社区的第三方模块列表:常见的第三方模块,但不仅限于这些
ngx-fancyindex介绍
基于默认官方模块autoindex,实现更加可定制化的功能。比如说,用户自定义头部和尾部、用户自己定义的css样式、允许通过名称、修改时间、大小对于元素进行排序(升序或者降序)。
使用默然官方index:

使用模块美化后:

2、编译安装第三方模块
实现操作步骤:
①重新编译安装加载第三方模块
记得先解压第三方软件模块
shell > tar zxvf ngx-fancyindex-v0.4.2.tar.gz
shell > cd /root/soft/nginx-1.14.0
shell > ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/root/soft/ngx-fancyindex-0.4.2/
shell > make && make install
安装完成之后

3、配置实现
②配置实现


③测试查看效果
测试配置文件,进行重载配置[如果是新编译的软件,就需要重启,因为旧的版本里没有加入新的第三方模块]。如果模块安装完成,配置成功,就可以看到之前图片的效果了
Tip:关于页脚footer的配置

页脚内容,可以根据需求进行编写,在配置文件root绑定的网站目录

上传一个二维码图片


最后显示效果
相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36