查看nginx默认安装了哪些模块

nginx是常用的一款web服务器,nginx是使用模块化的架构,在实际使用过程中我们要根据不同的需求,将不同的模块编辑到nginx里面去。但是在编译过程的时候,默认安装的模块有哪些呢?下面我们一起来看。

工具/原料

  • nginx压缩包

方法/步骤

1.下载nginx

在nginx官网上的下载页面找到linux最新版本的下载链接,我们一般是使用nginx的stable版本,即稳定版本。在下载链接上点右键,选择复制链接。

在这里插入图片描述

或者用命令下载

[root@centos8 ~]#wget https://nginx.org/download/nginx-1.18.0.tar.gz

2.解压并编译安装nginx

然后在需要编译安装nginx的linux主机上通过下面图中的命令将刚才复制的文件链接里的nginx压缩包下载下来。下载完成后,使用tar命令将nginx解压出来,解压好以后,在解压的目录中我们可以看到一个auto目录。

[root@centos8 ~]#tar xf nginx-1.18.0.tar.gz
[root@centos8 ~/nginx-1.18.0]#ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src


3.在这个auto目录中有一个options文件,这个文件里面保存的就是nginx编译过程中的所有选项配置。

[root@centos8 ~/nginx-1.18.0]#ls auto/
cc      endianness  have          headers  init     lib   module   nohave   os       stubs    threads  unix
define  feature     have_headers  include  install  make  modules  options  sources  summary  types

4.

如下面第一张图中所示,通过命令:

[root@centos8 ~]#cat nginx-1.18.0/auto/options | grep “YES”

1.找到所有编译状态默认是YES的模块,显示结果如图中所示。格式是:

module_name=YES

[root@centos8 ~]#cat nginx-1.18.0/auto/options | grep "YES"
HTTP=YES
HTTP_CACHE=YES
HTTP_CHARSET=YES
HTTP_GZIP=YES
HTTP_SSI=YES
HTTP_ACCESS=YES
HTTP_AUTH_BASIC=YES
HTTP_MIRROR=YES
HTTP_USERID=YES
HTTP_AUTOINDEX=YES
HTTP_GEO=YES
HTTP_MAP=YES
HTTP_SPLIT_CLIENTS=YES
HTTP_REFERER=YES
HTTP_REWRITE=YES
HTTP_PROXY=YES
HTTP_FASTCGI=YES
HTTP_UWSGI=YES
HTTP_SCGI=YES
HTTP_GRPC=YES
HTTP_MEMCACHED=YES
HTTP_LIMIT_CONN=YES
HTTP_LIMIT_REQ=YES
HTTP_EMPTY_GIF=YES
HTTP_BROWSER=YES
HTTP_UPSTREAM_HASH=YES
HTTP_UPSTREAM_IP_HASH=YES
HTTP_UPSTREAM_LEAST_CONN=YES
HTTP_UPSTREAM_RANDOM=YES
HTTP_UPSTREAM_KEEPALIVE=YES
HTTP_UPSTREAM_ZONE=YES
MAIL_POP3=YES
MAIL_IMAP=YES
MAIL_SMTP=YES
STREAM_LIMIT_CONN=YES
STREAM_ACCESS=YES
STREAM_GEO=YES
STREAM_MAP=YES
STREAM_SPLIT_CLIENTS=YES
STREAM_RETURN=YES
STREAM_UPSTREAM_HASH=YES
STREAM_UPSTREAM_LEAST_CONN=YES
STREAM_UPSTREAM_RANDOM=YES
STREAM_UPSTREAM_ZONE=YES

2.此外,还会显示出所有编译选项里包含YES字段的行,如下面所示,以–with开头的那些行,这些可以先不看。

        --with-select_module)            EVENT_SELECT=YES           ;;
        --with-poll_module)              EVENT_POLL=YES             ;;
        --with-threads)                  USE_THREADS=YES            ;;
        --with-file-aio)                 NGX_FILE_AIO=YES           ;;
        --with-http_ssl_module)          HTTP_SSL=YES               ;;
        --with-http_v2_module)           HTTP_V2=YES                ;;
        --with-http_realip_module)       HTTP_REALIP=YES            ;;
        --with-http_addition_module)     HTTP_ADDITION=YES          ;;
        --with-http_xslt_module)         HTTP_XSLT=YES              ;;
        --with-http_image_filter_module) HTTP_IMAGE_FILTER=YES      ;;
        --with-http_geoip_module)        HTTP_GEOIP=YES             ;;
        --with-http_sub_module)          HTTP_SUB=YES               ;;
        --with-http_dav_module)          HTTP_DAV=YES               ;;
        --with-http_flv_module)          HTTP_FLV=YES               ;;
        --with-http_mp4_module)          HTTP_MP4=YES               ;;
        --with-http_gunzip_module)       HTTP_GUNZIP=YES            ;;
        --with-http_gzip_static_module)  HTTP_GZIP_STATIC=YES       ;;
        --with-http_auth_request_module) HTTP_AUTH_REQUEST=YES      ;;
        --with-http_random_index_module) HTTP_RANDOM_INDEX=YES      ;;
        --with-http_secure_link_module)  HTTP_SECURE_LINK=YES       ;;
        --with-http_degradation_module)  HTTP_DEGRADATION=YES       ;;
        --with-http_slice_module)        HTTP_SLICE=YES             ;;
        --with-http_perl_module)         HTTP_PERL=YES              ;;
        --with-http_stub_status_module)  HTTP_STUB_STATUS=YES       ;;
        --with-mail)                     MAIL=YES                   ;;
        --with-mail_ssl_module)          MAIL_SSL=YES               ;;
            MAIL=YES
            MAIL_SSL=YES
        --with-stream)                   STREAM=YES                 ;;
        --with-stream_ssl_module)        STREAM_SSL=YES             ;;
        --with-stream_realip_module)     STREAM_REALIP=YES          ;;
        --with-stream_geoip_module)      STREAM_GEOIP=YES           ;;
                                         STREAM_SSL_PREREAD=YES     ;;
        --with-google_perftools_module)  NGX_GOOGLE_PERFTOOLS=YES   ;;
        --with-cpp_test_module)          NGX_CPP_TEST=YES           ;;
        --with-compat)                   NGX_COMPAT=YES             ;;
        --with-debug)                    NGX_DEBUG=YES              ;;
        --with-pcre)                     USE_PCRE=YES               ;;
        --with-pcre-jit)                 PCRE_JIT=YES               ;;
        --with-libatomic)                NGX_LIBATOMIC=YES          ;;
        --test-build-devpoll)            NGX_TEST_BUILD_DEVPOLL=YES ;;
        --test-build-eventport)          NGX_TEST_BUILD_EVENTPORT=YES ;;
        --test-build-epoll)              NGX_TEST_BUILD_EPOLL=YES   ;;
        --test-build-solaris-sendfilev)  NGX_TEST_BUILD_SOLARIS_SENDFILEV=YES ;;
[root@centos8 ~]#

5.既然说到所有默认安装的模块状态是YES,那么我们来验证一下:

1.我们通过grep命令找到HTTP_CACHE模块,可以看到它的搜索结果只有两个,分别是:

  • HTTP_CACHE=YES

  • –without-http_cache

[root@centos8 ~]#cat nginx-1.18.0/auto/options | grep "HTTP_CACHE"
HTTP_CACHE=YES
        --without-http-cache)            HTTP_CACHE=NO              ;;

第一个表示HTTP_CACHE是个默认安装的模块;
第二个选项表示禁用这个模块。
即默认安装的模块只有一个=YES的状态和一个–without的关闭开关。

2.然后再用grep命令查找select这个web事件处理模块,可以看到并没有

EVENT_SELECT=YES
这样一个选项,能看到的只有两个
–with-select_module
–without-select_module

[root@centos8 ~]#cat nginx-1.18.0/auto/options | grep "select"
        --with-select_module)            EVENT_SELECT=YES           ;;
        --without-select_module)         EVENT_SELECT=NONE          ;;
  --with-select_module               enable select module
  --without-select_module            disable select module

第一个是编译时启用这个模块;
第二个用来关闭这个模块。
即可选模块有两个开个,一个是–with开头的启用开关,一个是–without开头的禁用开关。

这就是默认安装的模块和可选模块的区别。其他的模块也是一样,大家可以在自己的电脑上验证一下。

6.在查询这些资料时,网络上其他文档里说,可以使用nginx -V命令来查看。实际上不一定。比如我这里使用configure命令进行配置时,只带了一个参数,如下面所示,命令是:

./configure --prefix=/apps/nginx

编译完成后,使用make && make install命令安装。安装完成后,使用

nginx -V

命令查看时,可以看到,只有一个–prefix=/apps/nginx参数,根本看不到默认安装的模块。因此这种方法只适合查看自己添加的参数、编译时附带的可选模块或三方模块。

[root@centos8 ~]#nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/echo-nginx-module



注意事项

nginx不同的版本安装的默认模块可能有区别,大家显示的和我的可能有差异。但是原理相同。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值