Nginx模块管理和进程管理


前言

Nginx和Apache一样,同样适用饿模块化管理,但是和Apache“热插拔”(每次添加模块的时候,不需要重新编译,只需要重新载入即可)的方式不同,Nginx每次添加一个模块或删除一个模块的话都需要重新编译才可以适用相应的功能模块。

上一篇(http://blog.csdn.net/xlgen157387/article/details/49908523)已经说了Nginx的主要模块包括core、event、http、mail和misc(杂项),而每一个模块根据需要又有很多模块,这5类模块只有core是不可以禁止,其他的模块可以根据实际情况进行选择。

选择适用Nginx的模块

在Nginx(1.8.0)目录下适用./configure –help可以查看哪些模块已经被安装:

[root@iZ94sni08orZ nginx-1.8.0]# ./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

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --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

  --with-threads                     enable thread pool support

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

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_spdy_module            enable ngx_http_spdy_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
   。。。省略部分

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  。。。省略部分
  ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_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

  --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

  --add-module=PATH                  enable an external module

  --with-cc=PATH                     set C compiler pathname
  --with-cpp=PATH                    set C preprocessor pathname
  --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, 。。。  ....省略部分

  --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@iZ94sni08orZ nginx-1.8.0]# 

在上边的信息中,–with-XXX表示启用,–without-XXX则表示禁用,咋这里边所有–with-XXX的模块在默认安装的时候都没有安装,而所有–without-XXX的模块则表示在默认安装是已经被选入的模块,因此,要注意这个规则。另外还有既有–with-XXX还有–without-XXX的,那么这个选择就不是我们选择的了,在安装的时候根据系统的情况会自己安装的。

Nginx安装第三方模块

在对Nginx进行configure配置编译的时候,有一个参数–add-module,就是用来调价第三方模块的,例如:

--add-module=/root/nginx-accesskey-2.0.3

这个是防盗链的模块,安装就这么简单。

Nginx的进程管理

Nginx分为Single和Master两种进程模式,Single为单进程方式工作,通过ngx_single_process_cycle完成,Master模型即是一个master进程和多个worker进程,在实际的开发过程中使用Master方式。

Nginx在运行在Linux内核版本2.6以上的机子上使用的是epoll模型,所谓epoll模型就是“老板和下属”的类型,老板接活下属来做。

相关内容