nginx的安装

1,,nginx的安装

为什么使用nginx我就不多说了,很优秀的,请再行google

在安装前,先安装pcre,安装zlib,安装openssl,以及一些其他包

1 yum install -y gcc gcc-c++ openssl-devel zlib-devel

安装pcre编译安装(在最后检测的时候会报错)

1 pcre:
2 wget http://120.52.73.47/nchc.dl.sourceforge.net/project/pcre/pcre/8.34/pcre-8.34.tar.gz
3 tar zxvf pcre-8.34.tar.gz
4 cd pcre-8.34
5 ./configure
6 make && make install

或者yum安装(在最后检测时候不会报错)

yum  install -y pcre pcre-devel

下载nginx,安装

1 cd /usr/local/src
 2 下载地址:http://nginx.org/download/
 3 wget   http://nginx.org/download/nginx-1.6.3.tar.gz
 4 tar -zxvf   nginx-1.6.3.tar.gz
 5 
 6 cd nginx-1.6.3
 7 编译
 8 ./configure   --prefix=/usr/local/nginx  --with-http_ssl_module  --with-http_gzip_static_module --with-http_stub_status_module   --with-debug
  9 make
10 make install

检测:出现如下错误,根据提示添加库

[root@ali nginx-1.6.3]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决:

ln -s  /usr/local/lib/libpcre.so.1 /lib64

查看已经编译的模块也就是查看编译的参数

1 [root@iZ940ao463eZ nginx-1.6.3]# /usr/local/nginx/sbin/nginx -V
2 nginx version: nginx/1.6.233 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
4 configure arguments: ./configure   --prefix=/usr/local/nginx  --with-http_ssl_module  --with-http_gzip_static_module --with-http_stub_status_module   --with-debug

说明一下nginx的模块:

nginx有两种模块,内置模块和第三方模块

内置模块:

内置模块即安装nginx软件时,本身就支持的功能模块。这些模块有些默认已经开启,有些未开启,您都可以在编译安装时指定。

内置的模块--with-xxxx-..._moudle编译的时候加上这样的参数就可以

查看所有模块列表

./configure --help

  1 [root@iZ940ao463eZ nginx-1.6.2]# ./configure --help
  2 
  3   --help                             print this message
  4 
  5   --prefix=PATH                      set installation prefix
  6   --sbin-path=PATH                   set nginx binary pathname
  7   --conf-path=PATH                   set nginx.conf pathname
  8   --error-log-path=PATH              set error log pathname
  9   --pid-path=PATH                    set nginx.pid pathname
 10   --lock-path=PATH                   set nginx.lock pathname
 11 
 12   --user=USER                        set non-privileged user for
 13                                      worker processes
 14   --group=GROUP                      set non-privileged group for
 15                                      worker processes
 16 
 17   --builddir=DIR                     set build directory
 18 
 19   --with-rtsig_module                enable rtsig module
 20   --with-select_module               enable select module
 21   --without-select_module            disable select module
 22   --with-poll_module                 enable poll module
 23   --without-poll_module              disable poll module
 24 
 25   --with-file-aio                    enable file AIO support
 26   --with-ipv6                        enable IPv6 support
 27 
 28   --with-http_ssl_module             enable ngx_http_ssl_module
 29   --with-http_spdy_module            enable ngx_http_spdy_module
 30   --with-http_realip_module          enable ngx_http_realip_module
 31   --with-http_addition_module        enable ngx_http_addition_module
 32   --with-http_xslt_module            enable ngx_http_xslt_module
 33   --with-http_image_filter_module    enable ngx_http_image_filter_module
 34   --with-http_geoip_module           enable ngx_http_geoip_module
 35   --with-http_sub_module             enable ngx_http_sub_module
 36   --with-http_dav_module             enable ngx_http_dav_module
 37   --with-http_flv_module             enable ngx_http_flv_module
 38   --with-http_mp4_module             enable ngx_http_mp4_module
 39   --with-http_gunzip_module          enable ngx_http_gunzip_module
 40   --with-http_gzip_static_module     enable ngx_http_gzip_static_module
 41   --with-http_auth_request_module    enable ngx_http_auth_request_module
 42   --with-http_random_index_module    enable ngx_http_random_index_module
 43   --with-http_secure_link_module     enable ngx_http_secure_link_module
 44   --with-http_degradation_module     enable ngx_http_degradation_module
 45   --with-http_stub_status_module     enable ngx_http_stub_status_module
 46 
 47   --without-http_charset_module      disable ngx_http_charset_module
 48   --without-http_gzip_module         disable ngx_http_gzip_module
 49   --without-http_ssi_module          disable ngx_http_ssi_module
 50   --without-http_userid_module       disable ngx_http_userid_module
 51   --without-http_access_module       disable ngx_http_access_module
 52   --without-http_auth_basic_module   disable ngx_http_auth_basic_module
 53   --without-http_autoindex_module    disable ngx_http_autoindex_module
 54   --without-http_geo_module          disable ngx_http_geo_module
 55   --without-http_map_module          disable ngx_http_map_module
 56   --without-http_split_clients_module disable ngx_http_split_clients_module
 57   --without-http_referer_module      disable ngx_http_referer_module
 58   --without-http_rewrite_module      disable ngx_http_rewrite_module
 59   --without-http_proxy_module        disable ngx_http_proxy_module
 60   --without-http_fastcgi_module      disable ngx_http_fastcgi_module
 61   --without-http_uwsgi_module        disable ngx_http_uwsgi_module
 62   --without-http_scgi_module         disable ngx_http_scgi_module
 63   --without-http_memcached_module    disable ngx_http_memcached_module
 64   --without-http_limit_conn_module   disable ngx_http_limit_conn_module
 65   --without-http_limit_req_module    disable ngx_http_limit_req_module
 66   --without-http_empty_gif_module    disable ngx_http_empty_gif_module
 67   --without-http_browser_module      disable ngx_http_browser_module
 68   --without-http_upstream_ip_hash_module
 69                                      disable ngx_http_upstream_ip_hash_module
 70   --without-http_upstream_least_conn_module
 71                                      disable ngx_http_upstream_least_conn_module
 72   --without-http_upstream_keepalive_module
 73                                      disable ngx_http_upstream_keepalive_module
 74 
 75   --with-http_perl_module            enable ngx_http_perl_module
 76   --with-perl_modules_path=PATH      set Perl modules path
 77   --with-perl=PATH                   set perl binary pathname
 78 
 79   --http-log-path=PATH               set http access log pathname
 80   --http-client-body-temp-path=PATH  set path to store
 81                                      http client request body temporary files
 82   --http-proxy-temp-path=PATH        set path to store
 83                                      http proxy temporary files
 84   --http-fastcgi-temp-path=PATH      set path to store
 85                                      http fastcgi temporary files
 86   --http-uwsgi-temp-path=PATH        set path to store
 87                                      http uwsgi temporary files
 88   --http-scgi-temp-path=PATH         set path to store
 89                                      http scgi temporary files
 90 
 91   --without-http                     disable HTTP server
 92   --without-http-cache               disable HTTP cache
 93 
 94   --with-mail                        enable POP3/IMAP4/SMTP proxy module
 95   --with-mail_ssl_module             enable ngx_mail_ssl_module
 96   --without-mail_pop3_module         disable ngx_mail_pop3_module
 97   --without-mail_imap_module         disable ngx_mail_imap_module
 98   --without-mail_smtp_module         disable ngx_mail_smtp_module
 99 
100   --with-google_perftools_module     enable ngx_google_perftools_module
101   --with-cpp_test_module             enable ngx_cpp_test_module
102 
103   --add-module=PATH                  enable an external module
104 
105   --with-cc=PATH                     set C compiler pathname
106   --with-cpp=PATH                    set C preprocessor pathname
107   --with-cc-opt=OPTIONS              set additional C compiler options
108   --with-ld-opt=OPTIONS              set additional linker options
109   --with-cpu-opt=CPU                 build for the specified CPU, valid values:
110                                      pentium, pentiumpro, pentium3, pentium4,
111                                      athlon, opteron, sparc32, sparc64, ppc64
112 
113   --without-pcre                     disable PCRE library usage
114   --with-pcre                        force PCRE library usage
115   --with-pcre=DIR                    set path to PCRE library sources
116   --with-pcre-opt=OPTIONS            set additional build options for PCRE
117   --with-pcre-jit                    build PCRE with JIT compilation support
118 
119   --with-md5=DIR                     set path to md5 library sources
120   --with-md5-opt=OPTIONS             set additional build options for md5
121   --with-md5-asm                     use md5 assembler sources
122 
123   --with-sha1=DIR                    set path to sha1 library sources
124   --with-sha1-opt=OPTIONS            set additional build options for sha1
125   --with-sha1-asm                    use sha1 assembler sources
126 
127   --with-zlib=DIR                    set path to zlib library sources
128   --with-zlib-opt=OPTIONS            set additional build options for zlib
129   --with-zlib-asm=CPU                use zlib assembler sources optimized
130                                      for the specified CPU, valid values:
131                                      pentium, pentiumpro
132 
133   --with-libatomic                   force libatomic_ops library usage
134   --with-libatomic=DIR               set path to libatomic_ops library sources
135 
136   --with-openssl=DIR                 set path to OpenSSL library sources
137   --with-openssl-opt=OPTIONS         set additional build options for OpenSSL
138 
139   --with-debug                       enable debug logging
View Code

具体每个用法说明如下:
转载自:http://luyafei.blog.51cto.com/1092421/1734767

可以看看这个:http://blog.lizhigang.net/archives/137

这个:http://tengine.taobao.org/nginx_docs/cn/docs/install.html

  1 # ./configure --help
  2  
  3 --prefix=PATH         //指定安装目录的路径
  4 --sbin-path=PATH      //指定可执行程序的安装路径
  5 --modules-path=PATH   //指定模块的安装路径
  6 --conf-path=PATH      //指定配置文件的路径
  7 --error-log-path=PATH //指定错误日志的路径
  8 --pid-path=PATH       //指定PID文件的路径
  9 --lock-path=PATH      //指定锁文件的安装路径
 10   
 11 --user=USER   //指定运行的用户
 12 --group=GROUP //指定运行的组
 13  
 14 --build=NAME  //设置编译名称
 15 --builddir=DIR //设置编译目录
 16  
 17 --with-select_module  //启用select模块支持,不建议启用
 18 --without-select_module //禁用select模块支持
 19 --with-poll_module    //启用poll模块支持,不建议启用
 20 --without-poll_module  //禁用poll模块支持
 21  
 22 --with-threads  //启用线程池支持
 23 --with-file-aio //文件AIO(异步I/O)模式支持,建议启用,在很大程度上可以提高系统的吞吐量
 24 --with-ipv6  //IPv6的支持
 25  
 26 --with-http_ssl_module        //启用支持ssl模式,也就是https,必须先安装openssl
 27 --with-http_v2_module         //支持HTTP2协议,取代ngx_http_spdy_module,谷歌spdy
 28 --with-http_realip_module     //允许请求包头更改客户端的ip地址
 29 --with-http_addition_module   //此模块是一个过滤器,添加文本之前和之后的反应。
 30 --with-http_xslt_module       //0.7.8以后的版本支持,这个模块是一个过滤器,使用一个或多个XSLT样式表转换XML响应。
 31 --with-http_image_filter_module //传输JPEG/GIF/PNG 图片的一个过滤器)(默认为不启用。gd库要用到)
 32  
 33 --with-http_geoip_module //模块(0.8.6+)创建变量,使用预编译的MaxMind数据库解析客户端IP地址,得到变量值
 34 --with-http_sub_module   //允许用一些其他文本替换nginx响应中的一些文本
 35 --with-http_dav_module   //增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认情况下为关闭,需编译开启
 36 --with-http_flv_module   //模块ngx_http_flv_module 为Flash Video(FLV)文件 提供服务端伪流媒体支持
 37 --with-http_mp4_module   //模块ngx_http_mp4_module为H.264/AAC文件,主要是以 .mp4、.m4v、和.m4a为扩展名的文件, 提供伪流媒体服务端支持。
 38  
 39 --with-http_gunzip_module  //ngx_http_gunzip_module模块是一个过滤器, 它为不支持“gzip”编码方法的客户端解压具有“Content-Encoding: gzip”头的响应。 当希望存储压缩后的数据以节省空间和减少I/O开销,又不希望对那些不支持gzip压缩的客户端造成不利影响时, 此模块会派上用途。
 40  
 41 --with-http_gzip_static_module  //模块 ngx_http_gzip_static_module 允许发送以“.gz”作为文件扩展名的预压缩文件,以替代发送普通文件。
 42 --with-http_auth_request_module //模块ngx_http_auth_request_modul(1.5.4+)实现了客户端的基本认证
 43 --with-http_random_index_module //显示随机首页模块支持
 44 --with-http_secure_link_module  //这个模块为一个必需的安全性令牌检查请求网址。要使用这个模块必须在编译时指定下列编译参数(0.7.18后版本可用)
 45 --with-http_degradation_module  //启用ngx_http_degradation_module支持(允许在内存不足的情况下返回204或444码)
 46 --with-http_slice_module  //ngx_http_slice_module模块(1.9.8)是一个过滤器,它将请求分为subrequests,每个返回一个特定范围的响应。大的过滤器提供了更有效的缓存响应。
 47 --with-http_stub_status_module //模块ngx_http_stub_status_module提供访问基本的状态信息
 48  
 49 --without-http_charset_module //禁用ngx_http_charset_module支持(重新编码web页面,但只能是一个方向--服务器端到客户端,并且只有一个字节的编码可以被重新编码)
 50 --without-http_gzip_module  //不编译http_gzip_module模块。该模块可以压缩HTTP服务器的响应,该模块需要zlib库才能编译和运行
 51 --without-http_ssi_module  //禁用ssi支持;ngx_http_ssi_module模块是一个过滤器处理SSI(服务器端包括)命令响应通过它。目前,支持的SSI命令列表是不完整的。
 52 --without-http_userid_module  //禁用ngx_http_userid_module,此模块适合客户端设置cookie识别。收到并设置cookie可以记录使用嵌入式变量$uid_got和$uid_set
 53 --without-http_access_module  //禁止ngx_http_access_module,此模块允许限制访问某些客户地址。
 54 --without-http_auth_basic_module  //禁止基本的认证模块,比如用户名密码
 55 --without-http_autoindex_module   //禁止ngx_http_autoindex_module模块流程请求以斜杠字符(“/”)和生成一个目录清单。通常一个请求传递给ngx_http_autoindex_module模块
 56 当ngx_http_index_module模块无法找到一个索引文件。满足指令。
 57 --without-http_geo_module  //禁止ngx_http_geo_module模块创建变量和值取决于客户端IP地址。
 58 --without-http_map_module  //禁止ngx_http_map_module模块创建变量的值取决于其他变量的值。
 59 --without-http_split_clients_module  //禁用ngx_http_split_clients_module支持(该模块用来基于某些条件划分用户。条件如:ip地址、报头、cookies等等)
 60 --without-http_referer_module  //禁用disable ngx_http_referer_module支持(该模块用来过滤请求,拒绝报头中Referer值不正确的请求)
 61 --without-http_rewrite_module  //禁用ngx_http_rewrite_module模块用于变更请求URI使用正则表达式,返回重定向,有条件地选择配置。
 62 --without-http_proxy_module  //禁用ngx_http_proxy_module支持(有关代理服务器)
 63 --without-http_fastcgi_module  //禁用ngx_http_fastcgi_module支持(该模块允许Nginx 与FastCGI 进程交互,并通过传递参数来控制FastCGI 进程工作。 )FastCGI一个常驻型的公共网关接口。
 64 --without-http_uwsgi_module  //禁用ngx_http_uwsgi_module支持(该模块用来医用uwsgi协议,uWSGI服务器相关)
 65 --without-http_scgi_module  //禁用ngx_http_scgi_module支持(该模块用来启用SCGI协议支持,SCGI协议是CGI协议的替代。它是一种应用程序与HTTP服务接口标准。
 66 它有些像FastCGI但他的设计 更容易实现。)
 67 --without-http_memcached_module  //禁用ngx_http_memcached_module支持(该模块用来提供简单的缓存,以提高系统效率)
 68 --without-http_limit_conn_module  //ngx_http_limit_conn_module 模块可以按照定义的键限定每个键值的连接数。特别的,可以设定单一 IP 来源的连接数。
 69 --without-http_limit_req_module  //ngx_http_limit_req_module模块(0.7.21)可以通过定义的 键值来限制请求处理的频率。特别的,它可以限制来自单个IP地址的请求处理频率。 限制的方法是通过一种“漏桶”的方法——固定每秒处理的请求数,推迟过多的请求处理。
 70  
 71 --without-http_empty_gif_module  //禁用ngx_http_empty_gif_module支持(该模块在内存中常驻了一个1*1的透明GIF图像,可以被非常快速的调用)
 72 --without-http_browser_module  //禁用ngx_http_browser_module支持(该模块用来创建依赖于请求报头的值。如果浏览器为modern ,则$modern_browser等于modern_browser_value指令分配的值;如 果浏览器为old,则$ancient_browser等于 ancient_browser_value指令分配的值;如果浏览器为 MSIE中的任意版本,则 $msie等于1)
 73 --without-http_upstream_hash_module  //禁用upstream哈希模块
 74  
 75 --without-http_upstream_ip_hash_module //禁用ngx_http_upstream_ip_hash_module支持(该模块用于简单的负载均衡)
 76 --without-http_upstream_least_conn_module //ngx_http_upstream_module模块是用来定义服务器组,可以引用proxy_pass,fastcgi_pass,uwsgi_pass,scgi_pass,
 77 memcached_pass指令。
 78 --without-http_upstream_keepalive_module //禁止upstream_keepalive此模块,启用keepalive为upstream servers
 79 --without-http_upstream_zone_module //禁用upstream的zone,如:upstream backend {}
 80  
 81  
 82 --with-http_perl_module //启用ngx_http_perl_module支持(该模块使nginx可以直接使用perl或通过ssi调用perl)
 83 --with-perl_modules_path=PATH //设定perl模块路径
 84 --with-perl=PATH  //设定perl库文件路径
 85  
 86 --http-log-path=PATH   //设定access log路径
 87 --http-client-body-temp-path=PATH //设定http客户端请求临时文件路径
 88 --http-proxy-temp-path=PATH  //定义了一个目录来存储临时文件的数据收到代理服务器。到三级子目录层次结构可以使用下面指定的目录。
 89 --http-fastcgi-temp-path=PATH  //设定http fastcgi临时文件路径
 90 --http-uwsgi-temp-path=PATH  //设定http uwsgi临时文件路径
 91 --http-scgi-temp-path=PATH  //设定http scgi临时文件路径
 92  
 93 --without-http   //禁用http server功能
 94 --without-http-cache //禁用http cache
 95  
 96 --with-mail   //启用POP3/IMAP/SMTP代理支持
 97 --with-mail_ssl_module //启用MAIL安全支持
 98 --without-mail_pop3_module //禁用POP3协议支持
 99 --without-mail_imap_module //禁用IMAP协议支持
100 --without-mail_smtp_module //禁用SMTP协议支持
101  
102 --with-stream  //这个模块在1.90版本后将被启用。但是并不会默认安装,需要在编译时通过指定,此模块支持TCP代理
103 --with-stream_ssl_module  //ngx_stream_ssl_module模块(1.9.0)提供了必要的支持流代理服务器的SSL/TLS协议。这个模块不是建立在默认情况下,
104 它应该是——with-stream_ssl_module配置参数启用。
105 --without-stream_limit_conn_module  //禁止ngx_stream_limit_conn_module模块()用来限制连接数/定义的关键,特别是从一个单一的IP地址的连接数量。
106 --without-stream_access_module  //禁止ngx_stream_access_module模块(1.9.2)允许限制访问某些客户地址。
107 --without-stream_upstream_hash_module  //禁止ngx_stream_upstream_module模块(1.9.0)是用于定义服务器组,可以引用proxy_pass指令。
108 --without-stream_upstream_least_conn_module  //禁止指定服务器组应该使用负载平衡方法传递给服务器的连接的活跃连接数最少的,考虑权重的服务器。如果有几个这样的服务器,
109 他们尝试使用加权循环平衡方法
110 --without-stream_upstream_zone_module  //
111  
112 --with-google_perftools_module //google-perftools包含四个工具,分别是:TCMalloc、heap-checker、heap-profiler和cpu-profiler,
113 TCMalloc是google-perftools的其中一个工具,用于优化内存分配的效率和速度,帮助在高并发的情况下很好的控制内存的使用。
114 --with-cpp_test_module  //
115  
116 --add-module=PATH   //增加第三方模块的支持
117 --add-dynamic-module=PATH  //动态模块的路径
118  
119 --with-cc=PATH  //指向C编译器的路径
120 --with-cpp=PATH //指向C预处理器的路径
121 --with-cc-opt=OPTIONS  //设置C编译器参数
122 --with-ld-opt=OPTIONS  //设置连接文件参数
123 --with-cpu-opt=CPU   //指定编译的CPU可用的值为: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
124  
125 --without-pcre  //禁用pcre库
126 --with-pcre     //启用pcre
127 --with-pcre=DIR  //指向pcre库的目录
128 --with-pcre-opt=OPTIONS //编译时为pcre库设置附加参数
129 --with-pcre-jit  //编译PCRE库时增加"实时编译(pcre_jit)"支持。
130  
131 --with-md5=DIR //指向md5库文件目录(消息摘要算法第五版,用以提供消息的完整性保护)
132 --with-md5-opt=OPTIONS //在编译时为md5库设置附加参数
133 --with-md5-asm //使用md5汇编源
134  
135 --with-sha1=DIR  //指向sha1库目录(数字签名算法,主要用于数字签名)
136 --with-sha1-opt=OPTIONS   //在编译时为sha1库设置附加参数
137 --with-sha1-asm  //使用sha1汇编源
138  
139 --with-zlib=DIR  //指向zlib库目录
140 --with-zlib-opt=OPTIONS //在编译时为zlib设置附加参数
141 --with-zlib-asm=CPU //为指定的CPU使用zlib汇编源进行优化,CPU类型为pentium, pentiumpro
142  
143 --with-libatomic //为原子内存的更新操作的实现提供一个架构
144 --with-libatomic=DIR //指向libatomic_ops安装目录
145 --with-openssl=DIR //指向openssl安装目录
146 --with-openssl-opt=OPTIONS //在编译时为openssl设置附加参数
147 --with-debug //启用debug日志
View Code

模块中有以with开头的,有以without开头的:重要(以with开头的为未开启的模块,以without开头的为已开启的模块)

开启禁用模块

1 > ./configure --with-http-xxx-module --without-http-yyy-module && make && make install

3、第三方模块

第三方模块:即为社区提供的模块功能,也是为了扩展nginx的功能,只是安装方式不一样而已。以nginx http push stream module为例,这是一个可以让nginx提供聊天通讯功能的模块。

下载源码并安装:

> git clone git@github.com:wandenberg/nginx-push-stream-module.git

> cd xxx/nginx-1.8.0  #切换到nginx目录

> ./configure --add-module=yyy/nginx-push-stream-module && make && make install

或者只是make而不需要make  install

# /usr/local/nginx/sbin/nginx -s stop
# cp objs/nginx /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -t   #检测下
#/usr/local/nginx/sbin/nginx       #启动

参考网址:http://www.ttlsa.com/nginx/how-to-install-nginx-third-modules/

http://nglua.com/articles/2.html

https://my.oschina.net/wojibuzhu/blog/113771

原文地址:https://www.cnblogs.com/Dicky-Zhang/p/5951117.html