歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Nginx模塊管理和進程管理

Nginx模塊管理和進程管理

日期:2017/3/1 12:20:45   编辑:關於Linux

前言

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模型就是“老板和下屬”的類型,老板接活下屬來做。

Copyright © Linux教程網 All Rights Reserved