Nginx 模块(1)

2021-10-18 11:55:33 浏览数 (1)

前言

Nginx (engine x) 可以作为 HTTP 和反向代理服务器,也可以作为邮件代理和普通的 TCP/UDP 代理服务器

由于其事件驱动的异步通讯机制在当前的web应用场景中性能非常卓越,所以被广泛使用,相关基础可以参考之前的一篇文章 nginx基础

Tip: 当前最新版本为 nginx-1.11.2 于 2016-07-05 发布

Tengine 是由淘宝网发起的Web服务器项目,它在 Nginx 的基础上,针对大访问量网站的需求,添加了很多高级功能和特性

相关基础可以参考之前的一篇文章 Tengine基础

Tip: 当前最新版本为 Tengine-2.1.2 于 2015-12-31 发布

模块化 是代码世界中一个极其重要的思想,将特定功能的代码组织在一起,通过统一的接口与主体对接,这样不仅精简了设计,明确了主体逻辑,让软件架构变得更健壮,甚至还能动态地扩展软件能力,和定制化缩减冗余功能,这样的设计可以更好的适应复杂多变的环境需求

很多优秀的软件都引入了这个思想,Nginx 也不例外,这里通过 Tengine 来介绍一下加载模块的相关基础,详细可以参考 Tengine 官方文档Nginx 官方文档


概要


环境

代码语言:javascript复制
[root@iZ11b0k6s5lZ ~]# hostnamectl 
   Static hostname: iZ11b0k6s5lZ
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 7d26c16f128042a684ea474c9e2c240f
           Boot ID: 8169ae94d80c4ae4b84c036d604ed2ce
    Virtualization: xen
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
[root@iZ11b0k6s5lZ ~]#  

下载

Tengine下载地址

代码语言:javascript复制
[root@iZ11b0k6s5lZ src]# wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
--2016-07-08 11:54:00--  http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
Resolving tengine.taobao.org (tengine.taobao.org)... 120.55.149.135
Connecting to tengine.taobao.org (tengine.taobao.org)|120.55.149.135|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2137295 (2.0M) [application/octet-stream]
Saving to: ‘tengine-2.1.2.tar.gz’

100%[=======================================================================================>] 2,137,295   1.52MB/s   in 1.3s   

2016-07-08 11:54:01 (1.52 MB/s) - ‘tengine-2.1.2.tar.gz’ saved [2137295/2137295]

[root@iZ11b0k6s5lZ src]# md5sum tengine-2.1.2.tar.gz 
7f898a0dbb5162ff1eb19aeb9d53bec3  tengine-2.1.2.tar.gz
[root@iZ11b0k6s5lZ src]#

Tip: 下载后,可以使用 md5sum 计算一下包的值,和官网给出的值进行一下比对,可以起到简单校验的效果


依赖包

下面是依赖的包

代码语言:javascript复制
pcre.x86_64   
pcre-devel.x86_64  
zlib.x86_64  
zlib-devel.x86_64 
openssl.x86_64 
openssl-devel.x86_64

使用 yum 进行安装

代码语言:javascript复制
[root@iZ11b0k6s5lZ src]# yum install  pcre.x86_64  pcre-devel.x86_64  zlib.x86_64  zlib-devel.x86_64 openssl.x86_64 openssl-devel.x86_64
Loaded plugins: fastestmirror
base                                                                                                      | 3.6 kB  00:00:00     
epel                                                                                                      | 4.3 kB  00:00:00     
extras                                                                                                    | 3.4 kB  00:00:00     
updates                                                                                                   | 3.4 kB  00:00:00     
updates/7/x86_64/primary_db                                                                               | 5.7 MB  00:00:05     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * epel: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
Package pcre-8.32-15.el7_2.1.x86_64 already installed and latest version
Package pcre-devel-8.32-15.el7_2.1.x86_64 already installed and latest version
Package zlib-1.2.7-15.el7.x86_64 already installed and latest version
Package zlib-devel-1.2.7-15.el7.x86_64 already installed and latest version
Package 1:openssl-1.0.1e-51.el7_2.5.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.1e-51.el7_2.5.x86_64 already installed and latest version
Nothing to do
[root@iZ11b0k6s5lZ src]#

Note: 如果缺少上面的包,在编译检查的过程中,可能会报错


解压

代码语言:javascript复制
[root@iZ11b0k6s5lZ src]# ls
tengine-2.1.2.tar.gz
[root@iZ11b0k6s5lZ src]# tar -zxvf tengine-2.1.2.tar.gz 
tengine-2.1.2/
tengine-2.1.2/good_configure
tengine-2.1.2/configure
tengine-2.1.2/docs/
tengine-2.1.2/docs/modules/
tengine-2.1.2/docs/modules/ngx_http_tfs_module_cn.md
...
...
tengine-2.1.2/tests/test-nginx/dso_cases/ngx_http_upstream_check_module/
tengine-2.1.2/tests/test-nginx/dso_cases/ngx_http_upstream_check_module/check_interface.t
tengine-2.1.2/tests/test-nginx/dso_cases/ngx_http_upstream_check_module/tcp_check.t
tengine-2.1.2/tests/test-nginx/dso_cases/ngx_http_upstream_check_module/ssl_hello_check.t
tengine-2.1.2/tests/test-nginx/dso_cases/ngx_http_upstream_check_module/http_check.t
[root@iZ11b0k6s5lZ src]# 

配置

与配置参数相关的详细信息可以参考 Building nginx from SourcesTengine 的编译和安装

这里来看看 configure 可以接哪些参数

代码语言:javascript复制
[root@iZ11b0k6s5lZ src]# ls
tengine-2.1.2  tengine-2.1.2.tar.gz
[root@iZ11b0k6s5lZ src]# cd tengine-2.1.2
[root@iZ11b0k6s5lZ tengine-2.1.2]# ls
AUTHORS.te  CHANGES     CHANGES.ru  conf       contrib  good_configure  LICENSE  modules   README           src    THANKS.te
auto        CHANGES.cn  CHANGES.te  configure  docs     html            man      packages  README.markdown  tests
[root@iZ11b0k6s5lZ tengine-2.1.2]# ./configure  --help 

  --help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --builddir=DIR                     set build directory

  --enable-mods-shared=all           enable all the modules to be shared
  --enable-mods-static=all           enable all the modules to be static

  --dso-path=DIR                     set dso default load path
  --dso-tool-path=DIR                set dso_tool pathname
  --dso-max-modules=*)               set max dso module(default is 256)
  --includedir=DIR                   set C header files[PREFIX/include]

  --with-rtsig_module                enable rtsig module
  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --without-procs                    disable procs module

  --with-file-aio                    enable file AIO support
  --with-ipv6                        enable IPv6 support

  --without-syslog                   disable syslog logging

  --without-dso                      disable dso module load

  --with-http_spdy_module            enable ngx_http_spdy_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_filter_module
  --with-http_xslt_module            enable ngx_http_xslt_filter_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_filter_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_concat_module          enable ngx_http_concat_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_sysguard_module        enable ngx_http_sysguard_module

  --with-http_addition_module=shared enable ngx_http_addition_filter_module (shared)
  --with-http_xslt_module=shared     enable ngx_http_xslt_filter_module (shared)
  --with-http_image_filter_module=shared
                                     enable ngx_http_image_filter_module (shared)
  --with-http_geoip_module=shared    enable ngx_http_geoip_module
  --with-http_sub_module=shared      enable ngx_http_sub_filter_module (shared)
  --with-http_flv_module=shared      enable ngx_http_flv_module (shared)
  --with-http_slice_module=shared    enable ngx_http_slice_module (shared)
  --with-http_mp4_module=shared      enable ngx_http_mp4_module (shared)
  --with-http_concat_module=shared   enable ngx_http_concat_module (shared)
  --with-http_random_index_module=shared
                                     enable ngx_http_random_index_module (shared)
  --with-http_secure_link_module=shared
                                     enable ngx_http_secure_link_module (shared)
  --with-http_sysguard_module=shared enable ngx_http_sysguard_module (shared)
  --with-http_charset_filter_module=shared
                                     enable ngx_http_charset_filter_module (shared)
  --with-http_userid_filter_module=shared
                                     enable ngx_http_userid_filter_module (shared)
  --with-http_footer_filter_module=shared
                                     enable ngx_http_footer_filter_module (shared)
  --with-http_trim_filter_module=shared
                                     enable ngx_http_trim_filter_module (shared)
  --with-http_access_module=shared   enable ngx_http_access_module (shared)
  --with-http_autoindex_module=shared
                                     enable ngx_http_autoindex_module (shared)
  --with-http_map_module=shared      enable ngx_http_map_module (shared)
  --with-http_split_clients_module=shared
                                     enable ngx_http_split_clients_module (shared)
  --with-http_referer_module=shared  enable ngx_http_referer_module (shared)
  --with-http_rewrite_module=shared  enable ngx_http_rewrite_module (shared)
  --with-http_fastcgi_module=shared  enable ngx_http_fastcgi_module (shared)
  --with-http_uwsgi_module=shared    enable ngx_http_uwsgi_module (shared)
  --with-http_scgi_module=shared     enable ngx_http_scgi_module (shared)
  --with-http_memcached_module=shared
                                     enable ngx_http_memcached_module (shared)
  --with-http_limit_conn_module=shared
                                     enable ngx_http_limit_conn_module (shared)
  --with-http_limit_req_module=shared
                                     enable ngx_http_limit_req_module (shared)
  --with-http_empty_gif_module=shared
                                     enable ngx_http_empty_gif_module (shared)
  --with-http_browser_module=shared  enable ngx_http_browser_module (shared)
  --with-http_user_agent_module=shared
                                     enable ngx_http_user_agent_module (shared)
  --with-http_upstream_ip_hash_module=shared
                                     enable ngx_http_upstream_ip_hash_module (shared)
  --with-http_upstream_least_conn_module=shared
                                     enable ngx_http_upstream_least_conn_module (shared)
  --with-http_upstream_session_sticky_module=shared
                                     enable ngx_http_upstream_session_sticky_module (shared)
  --with-http_reqstat_module=shared  enable ngx_http_reqstat_module (shared)

  --without-http_charset_module      disable ngx_http_charset_filter_module
  --without-http_gzip_module         disable ngx_http_gzip_filter_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_ssl_module          disable ngx_http_ssl_module
  --without-http_userid_module       disable ngx_http_userid_filter_module
  --without-http_footer_filter_module
                                     disable ngx_http_footer_filter_module
  --without-http_trim_filter_module  disable ngx_http_trim_filter_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module
                                     disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_check_module
                                     disable ngx_http_upstream_check_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_session_sticky_module
                                     disable ngx_http_upstream_session_sticky_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_dynamic_module
                                     disable ngx_http_upstream_dynamic_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_consistent_hash_module
                                     disable ngx_http_upstream_consistent_hash_module
  --without-http_user_agent_module   disable ngx_http_user_agent_module
  --without-http_stub_status_module  disable ngx_http_stub_status_module
  --without-http_reqstat_module      disable ngx_http_reqstat_module

  --with-http_dyups_module           enable ngx_http_dyups_module
  --with-http_dyups_lua_api          enable lua api of ngx_http_dyups_module

  --with-http_perl_module            enable ngx_http_perl_module
  --with-perl_modules_path=PATH      set Perl modules path
  --with-perl=PATH                   set perl binary pathname

  --without-http-upstream-rbtree     disable using rbtree for upstream lookup

  --with-http_lua_module             enable ngx_http_lua_module (will also enable --with-md5 and --with-sha1)
  --with-http_lua_module=shared      enable ngx_http_lua_module (shared) (will also enable --with-md5 and --with-sha1)
  --with-luajit-inc=PATH             set LuaJIT headers path (where lua.h/lauxlib.h/... are located)
  --with-luajit-lib=PATH             set LuaJIT library path (where libluajit-5.1.{a,so} are located)
  --with-lua-inc=PATH                set Lua headers path (where lua.h/lauxlib.h/... are located)
  --with-lua-lib=PATH                set Lua library path (where liblua.{a,so} are located, only support Lua-5.1.x)

  --with-http_tfs_module             enable ngx_http_tfs_module (will also enable --with-md5)
  --with-http_tfs_module=shared      enable ngx_http_tfs_module (shared) (will also enable --with-md5)
  --with-libyajl-inc=PATH            set libyajl headers path (where yajl.h is located)
  --with-libyajl-lib=PATH            set libyajl library path (where libyajl.{a,so} is located)

  --http-log-path=PATH               set http access log pathname
  --http-client-body-temp-path=PATH  set path to store
                                     http client request body temporary files
  --http-proxy-temp-path=PATH        set path to store
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH      set path to store
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        set path to store
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH         set path to store
                                     http scgi temporary files

  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache

  --with-mail                        enable POP3/IMAP4/SMTP proxy module
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module

  --with-google_perftools_module     enable ngx_google_perftools_module
  --with-cpp_test_module             enable ngx_cpp_test_module
  --with-backtrace_module            enable ngx_backtrace_module

  --add-module=PATH                  enable an external module

  --with-cc=PATH                     set C compiler pathname
  --with-cpp=PATH                    set C preprocessor pathname
  --with-link=LINK                   set C linker
  --with-cc-opt=OPTIONS              set additional C compiler options
  --with-ld-opt=OPTIONS              set additional linker options
  --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64

  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                    set path to PCRE library sources
  --with-pcre-opt=OPTIONS            set additional build options for PCRE
  --with-pcre-jit                    build PCRE with JIT compilation support

  --with-md5=DIR                     set path to md5 library sources
  --with-md5-opt=OPTIONS             set additional build options for md5
  --with-md5-asm                     use md5 assembler sources

  --with-sha1=DIR                    set path to sha1 library sources
  --with-sha1-opt=OPTIONS            set additional build options for sha1
  --with-sha1-asm                    use sha1 assembler sources

  --with-zlib=DIR                    set path to zlib library sources
  --with-zlib-opt=OPTIONS            set additional build options for zlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     for the specified CPU, valid values:
                                     pentium, pentiumpro

  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR               set path to libatomic_ops library sources

  --with-jemalloc                    force jemalloc library usage
  --with-jemalloc=DIR                set path to jemalloc library files

  --with-openssl=DIR                 set path to OpenSSL library sources
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL

  --with-debug                       enable debug logging

[root@iZ11b0k6s5lZ tengine-2.1.2]#

0 人点赞