版权声明:本文为博主原创文章,未经博主允许不得转载。

从官网下载一个nginx 的tar.gz 版。

安装方式使用make 安装

第一步:解压

tar -zxvf  nginx-1.7.4.tar.gz

第二步:进入nginx-1.7.4,执行./configure 命令

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[root@localhost nginx-1.7.4]# ./configure
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found

出现这个错误。

那么就是gcc 包没有安装。安装gcc 吧,骚年。

yum  -y install gcc

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

再次执行./configure

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

yum install pcre-devel

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

再次执行./configure
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
yum install zlib-devel

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

再次执行./configure

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

OK,现在可以执行make 了。
如果你想使用openssl 功能,sha1 功能。
那么安装openssl ,sha1 吧,骚年。
安装openssl
yum install openssl openssl-devel
安装sha1
 

yum install perl-Digest-SHA1.x86_64

开启ssl 模块   执行./configure --with-http_ssl_module

启用“server+status"页,执行./configure --with-http_stub_status_module

两个都启动,不用我说了。执行./configure --with-http_stub_status_module --with-http_ssl_module

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

那么configre 就通过了。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

执行make 命令

执行make install 命令

至此,nginx 执行成功了

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

下来配置环境变量
在/etc/profile 中加入:
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
保存,
执行 source /etc/profile ,使配置文件生效。
执行nginx -v,就能看到版本了,说明nginx 安装成功了
 
 更改好后,重启nginx。
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
HUP信号是平滑重启
 

停止nginx

  1. kill  `cat /usr/local/nginx/logs/nginx.pid`

一、必要软件准备
1.安装pcre

为了支持rewrite功能,我们需要安装pcre

复制代码 代码如下:
# yum install pcre* //如过你已经装了,请跳过这一步

2.安装openssl

需要ssl的支持,如果不需要ssl支持,请跳过这一步

复制代码 代码如下:
# yum install openssl*

3.gzip 类库安装

复制代码 代码如下:
yum install zlib zlib-devel

4.安装wget

下载nginx使用,如果已经安装,跳过这一步

复制代码 代码如下:
# yum install wget

二、安装nginx

1.下载

复制代码 代码如下:
wget http://nginx.org/download/nginx-1.7.0.tar.gz

2.解压

复制代码 代码如下:
tar -zxvf nginx-1.7.0.tar.gz

3.编译和安装
执行如下命令:

复制代码 代码如下:
# cd nginx-1.7.0
# ./configure --prefix=/usr/local/nginx-1.7.0 \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre

–with-http_stub_status_module:支持nginx状态查询
–with-http_ssl_module:支持https
–with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
–with-pcre:为了支持rewrite重写功能,必须制定pcre

最后输出如下内容,表示configure OK了。

复制代码 代码如下:
checking for zlib library ... found
 creating objs/Makefile
Configuration summary
 + using system PCRE library
 + using system OpenSSL library
 + md5: using OpenSSL library
 + sha1: using OpenSSL library
 + using system zlib library
nginx path prefix: "/usr/local/nginx-1.7.0"
 nginx binary file: "/usr/local/nginx-1.7.0/sbin/nginx"
 nginx configuration prefix: "/usr/local/nginx-1.7.0/conf"
 nginx configuration file: "/usr/local/nginx-1.7.0/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx-1.7.0/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx-1.7.0/logs/error.log"
 nginx http access log file: "/usr/local/nginx-1.7.0/logs/access.log"
 nginx http client request body temporary files: "client_body_temp"
 nginx http proxy temporary files: "proxy_temp"
 nginx http fastcgi temporary files: "fastcgi_temp"
 nginx http uwsgi temporary files: "uwsgi_temp"
 nginx http scgi temporary files: "scgi_temp"
# make //确定你的服务器有安装make,如果没有安装请执行yum install make

# make install

三、启动、关闭、重置nginx

启动:直接执行以下命令,nginx就启动了,不需要改任何配置文件,nginx配置多域名虚拟主机请参考后续文章.

复制代码 代码如下:
/usr/local/nginx-1.7.0/sbin/nginx

试试访问:直接使用curl命令来读取web信息

复制代码 代码如下:
[root@ns conf]
# curl -s http://localhost | grep nginx.com
nginx.com.

关闭:

复制代码 代码如下:
/usr/local/nginx-1.7.0/sbin/nginx -s stop

重置:当你有修改配置文件的时候,只需要reload以下即可

复制代码 代码如下:
/usr/local/nginx-1.7.0/sbin/nginx -s reload

整个nginx的安装就到这里结束了。

四、nginx编译参数详解

复制代码 代码如下:
–prefix= 指向安装目录
–sbin-path 指向(执行)程序文件(nginx)
–conf-path= 指向配置文件(nginx.conf)
–error-log-path= 指向错误日志目录
–pid-path= 指向pid文件(nginx.pid)
–lock-path= 指向lock文件(nginx.lock)(安装文件锁定,防止安装文件被别人利用,或自己误操作。)
–user= 指定程序运行时的非特权用户
–group= 指定程序运行时的非特权用户组
–builddir= 指向编译目录
–with-rtsig_module 启用rtsig模块支持(实时信号)
–with-select_module 启用select模块支持(一种轮询模式,不推荐在高载环境下使用)禁用:–without-select_module
–with-poll_module 启用poll模块支持(功能与select相同,与select特性相同,为一种轮询模式,不推荐在高载环境下使用)
–with-file-aio 启用file aio支持(一种APL文件传输格式)
–with-ipv6 启用ipv6支持
–with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
–with-http_realip_module 启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
–with-http_addition_module 启用ngx_http_addition_module支持(作为一个输出过滤器,支持不完全缓冲,分部分响应请求)
–with-http_xslt_module 启用ngx_http_xslt_module支持(过滤转换XML请求)
–with-http_image_filter_module 启用ngx_http_image_filter_module支持(传输JPEG/GIF/PNG 图片的一个过滤器)(默认为不启用。gd库要用到)
–with-http_geoip_module 启用ngx_http_geoip_module支持(该模块创建基于与MaxMind GeoIP二进制文件相配的客户端IP地址的ngx_http_geoip_module变量)
–with-http_sub_module 启用ngx_http_sub_module支持(允许用一些其他文本替换nginx响应中的一些文本)
–with-http_dav_module 启用ngx_http_dav_module支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认情况下为关闭,需编译开启
–with-http_flv_module 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
–with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
–with-http_random_index_module 启用ngx_http_random_index_module支持(从目录中随机挑选一个目录索引)
–with-http_secure_link_module 启用ngx_http_secure_link_module支持(计算和检查要求所需的安全链接网址)
–with-http_degradation_module  启用ngx_http_degradation_module支持(允许在内存不足的情况下返回204或444码)
–with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
–without-http_charset_module 禁用ngx_http_charset_module支持(重新编码web页面,但只能是一个方向–服务器端到客户端,并且只有一个字节的编码可以被重新编码)
–without-http_gzip_module 禁用ngx_http_gzip_module支持(该模块同-with-http_gzip_static_module功能一样)
–without-http_ssi_module 禁用ngx_http_ssi_module支持(该模块提供了一个在输入端处理处理服务器包含文件(SSI)的过滤器,目前支持SSI命令的列表是不完整的)
–without-http_userid_module 禁用ngx_http_userid_module支持(该模块用来处理用来确定客户端后续请求的cookies)
–without-http_access_module 禁用ngx_http_access_module支持(该模块提供了一个简单的基于主机的访问控制。允许/拒绝基于ip地址)
–without-http_auth_basic_module禁用ngx_http_auth_basic_module(该模块是可以使用用户名和密码基于http基本认证方法来保护你的站点或其部分内容)
–without-http_autoindex_module 禁用disable ngx_http_autoindex_module支持(该模块用于自动生成目录列表,只在ngx_http_index_module模块未找到索引文件时发出请求。)
–without-http_geo_module 禁用ngx_http_geo_module支持(创建一些变量,其值依赖于客户端的IP地址)
–without-http_map_module 禁用ngx_http_map_module支持(使用任意的键/值对设置配置变量)
–without-http_split_clients_module 禁用ngx_http_split_clients_module支持(该模块用来基于某些条件划分用户。条件如:ip地址、报头、cookies等等)
–without-http_referer_module 禁用disable ngx_http_referer_module支持(该模块用来过滤请求,拒绝报头中Referer值不正确的请求)
–without-http_rewrite_module

禁用ngx_http_rewrite_module支持(该模块允许使用正则表达式改变URI,并且根据变量来转向以及选择配置。如果在server级
别设置该选项,那么他们将在
location之前生效。如果在location还有更进一步的重写规则,location部分的规则依然会被执行。如果这个URI重写是因为
location部分的规则造成的,那么 location部分会再次被执行作为新的URI。
这个循环会执行10次,然后Nginx会返回一个500错误。)
–without-http_proxy_module 禁用ngx_http_proxy_module支持(有关代理服务器)
–without-http_fastcgi_module 禁用ngx_http_fastcgi_module支持(该模块允许Nginx 与FastCGI 进程交互,并通过传递参数来控制FastCGI 进程工作。 )FastCGI一个常驻型的公共网关接口。
–without-http_uwsgi_module 禁用ngx_http_uwsgi_module支持(该模块用来医用uwsgi协议,uWSGI服务器相关)
–without-http_scgi_module 禁用ngx_http_scgi_module支持(该模块用来启用SCGI协议支持,SCGI协议是CGI协议的替代。它是一种应用程序与HTTP服务接口标准。它有些像FastCGI但他的设计 更容易实现。)
–without-http_memcached_module 禁用ngx_http_memcached_module支持(该模块用来提供简单的缓存,以提高系统效率)
-without-http_limit_zone_module 禁用ngx_http_limit_zone_module支持(该模块可以针对条件,进行会话的并发连接数控制)
–without-http_limit_req_module 禁用ngx_http_limit_req_module支持(该模块允许你对于一个地址进行请求数量的限制用一个给定的session或一个特定的事件)
–without-http_empty_gif_module 禁用ngx_http_empty_gif_module支持(该模块在内存中常驻了一个1*1的透明GIF图像,可以被非常快速的调用)
–without-http_browser_module
禁用ngx_http_browser_module支持(该模块用来创建依赖于请求报头的值。如果浏览器为modern
,则$modern_browser等于modern_browser_value指令分配的值;如
果浏览器为old,则$ancient_browser等于 ancient_browser_value指令分配的值;如果浏览器为
MSIE中的任意版本,则 $msie等于1)
–without-http_upstream_ip_hash_module 禁用ngx_http_upstream_ip_hash_module支持(该模块用于简单的负载均衡)
–with-http_perl_module 启用ngx_http_perl_module支持(该模块使nginx可以直接使用perl或通过ssi调用perl)
–with-perl_modules_path= 设定perl模块路径
–with-perl= 设定perl库文件路径
–http-log-path= 设定access log路径
–http-client-body-temp-path= 设定http客户端请求临时文件路径
–http-proxy-temp-path= 设定http代理临时文件路径
–http-fastcgi-temp-path= 设定http fastcgi临时文件路径
–http-uwsgi-temp-path= 设定http uwsgi临时文件路径
–http-scgi-temp-path= 设定http scgi临时文件路径
-without-http 禁用http server功能
–without-http-cache 禁用http cache功能
–with-mail 启用POP3/IMAP4/SMTP代理模块支持
–with-mail_ssl_module 启用ngx_mail_ssl_module支持
–without-mail_pop3_module

禁用pop3协议(POP3即邮局协议的第3个版本,它是规定个人计算机如何连接到互联网上的邮件服务器进行收发邮件的协议。是因特网电子邮件的第一个离
线协议标
准,POP3协议允许用户从服务器上把邮件存储到本地主机上,同时根据客户端的操作删除或保存在邮件服务器上的邮件。POP3协议是TCP/IP协议族中
的一员,主要用于 支持使用客户端远程管理在服务器上的电子邮件)
–without-mail_imap_module
禁用imap协议(一种邮件获取协议。它的主要作用是邮件客户端可以通过这种协议从邮件服务器上获取邮件的信息,下载邮件等。IMAP协议运行在
TCP/IP协议之上,
使用的端口是143。它与POP3协议的主要区别是用户可以不用把所有的邮件全部下载,可以通过客户端直接对服务器上的邮件进行操作。)
–without-mail_smtp_module

禁用smtp协议(SMTP即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式。SMTP协议属于
TCP/IP协议族,它帮助每台计算机在发送或中转信件时找到下一个目的地。)
–with-google_perftools_module 启用ngx_google_perftools_module支持(调试用,剖析程序性能瓶颈)
–with-cpp_test_module 启用ngx_cpp_test_module支持
–add-module= 启用外部模块支持
–with-cc= 指向C编译器路径
–with-cpp= 指向C预处理路径
–with-cc-opt=
设置C编译器参数(PCRE库,需要指定–with-cc-opt=”-I
/usr/local/include”,如果使用select()函数则需要同时增加文件描述符数量,可以通过–with-cc- opt=”-D
FD_SETSIZE=2048”指定。)
–with-ld-opt= 设置连接文件参数。(PCRE库,需要指定–with-ld-opt=”-L /usr/local/lib”。)
–with-cpu-opt= 指定编译的CPU,可用的值为: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
–without-pcre 禁用pcre库
–with-pcre 启用pcre库
–with-pcre= 指向pcre库文件目录
–with-pcre-opt= 在编译时为pcre库设置附加参数
–with-md5= 指向md5库文件目录(消息摘要算法第五版,用以提供消息的完整性保护)
–with-md5-opt= 在编译时为md5库设置附加参数
–with-md5-asm 使用md5汇编源
–with-sha1= 指向sha1库目录(数字签名算法,主要用于数字签名)
–with-sha1-opt= 在编译时为sha1库设置附加参数
–with-sha1-asm 使用sha1汇编源
–with-zlib= 指向zlib库目录
–with-zlib-opt= 在编译时为zlib设置附加参数
–with-zlib-asm= 为指定的CPU使用zlib汇编源进行优化,CPU类型为pentium, pentiumpro
–with-libatomic 为原子内存的更新操作的实现提供一个架构
–with-libatomic= 指向libatomic_ops安装目录
–with-openssl= 指向openssl安装目录
–with-openssl-opt 在编译时为openssl设置附加参数
–with-debug 启用debug日志

 
 

Nginx启动出错 error while loading shared libraries:

在centos5.7 32位上编译安照 nginx-1.1.16 出错

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

从错误看出是缺少lib文件导致,进一步查看下

[root@localhost conf]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-gate.so.1 => (0x0071b000)
libpthread.so.0 => /lib/libpthread.so.0 (0×00498000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0×00986000)
libpcre.so.1 => not found
libcrypto.so.6 => /lib/libcrypto.so.6 (0×00196000)
libz.so.1 => /lib/libz.so.1 (0×00610000)
libc.so.6 => /lib/libc.so.6 (0x002d7000)
/lib/ld-linux.so.2 (0x006a8000)
libdl.so.2 => /lib/libdl.so.2 (0x008c3000)

可以看出 libpcre.so.1 => not found 并没有找到,进入/lib目录中手动链接下

[root@localhost lib]# ln -s libpcre.so.0.0.1 libpcre.so.1

然后在启动nginx ok 了
 
[root@localhost lib]# /usr/local/nginx/sbin/nginx
[root@localhost lib]# ps -ef |grep nginx
root 9539 1 0 19:06 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 9540 9539 0 19:06 ? 00:00:00 nginx: worker process

 

【转】 linux 安装nginx及编译参数详解的更多相关文章

  1. Linux下nginx编译安装教程和编译参数详解

    这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...

  2. Linux安装svn服务图文详解 ;出现No repository found in 'svn***问题

    Linux安装svn服务 ** 示例都是用的root权限,可选择用 sudo** 1:检查 安装条件为:Linux(centos)上未安装过svn服务,若安装过或安装失败请自行删除,这里不多介绍.检查 ...

  3. Spark学习笔记--Linux安装Spark集群详解

    本文主要讲解如何在Linux环境下安装Spark集群,安装之前我们需要Linux已经安装了JDK和Scala,因为Spark集群依赖这些.下面就如何安装Spark进行讲解说明. 一.安装环境 操作系统 ...

  4. nginx 的编译参数详解

    内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...

  5. 快速安装Nginx及配置详解(未完待续)

    导读: Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,从2007年被德国人开发出来后可以说在市场的占有率一路飙升,因为它支持高并 ...

  6. Linux安装vsftpd及配置详解

    1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件.[root@bogon ~]# yum -y install vsftpd 2.FT ...

  7. Linux下PHP5.5编译参数详解

    一.配置参数 ./configure --prefix=/data/app/php --with-config-file-path=/etc --with-mysql=/usr\ --with-mys ...

  8. Linux centos7环境下安装JDK的步骤详解

    Linux centos7环境下安装JDK的步骤详解 测试root用户下JAVA版本 输入命令:   java –version 1.先到Oracle官网里下载好jdk,网址如下: http://ww ...

  9. Linux centos7环境下安装MySQL的步骤详解

    Linux centos7环境下安装MySQL的步骤详解 安装MySQL mysql 有两个跟windows不同的地方 1).my.ini 保存到/etc/my.ini 2).用户权限,单独用户执行 ...

随机推荐

  1. mysql连接字符串

    MySQL中 concat 函数使用方法:CONCAT(str1,str2,…)

  2. C++调用C中编译过的函数要加extern "C"

    C++语言支持函数重载,C语言不支持函数重载.函数被C++编译后在库中的名字与C语言的不同.假设某个C 函数的声明如下:void foo(int x, int y);该函数被C 编译器编译后在库中的名 ...

  3. python 练习 27

    ython continue 语句跳出本次循环,而break跳出整个循环. continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环. continue语句用在whil ...

  4. q和blockquote标签的区别

    q用来分离文本中的引语,定义一个短的引用.该标签会对引用的文本加双引号,一般情况很少用,博客论坛系统会用得多一些: blockquote用于对长文本的引用,用来定义一段引语,标签内的内容会自动有缩进: ...

  5. 128. Longest Consecutive Sequence *HARD* -- 寻找无序数组中最长连续序列的长度

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  6. UserAgent:通过浏览器获取用户浏览器等信息

    User Agent的含义      User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本.CPU 类型.浏览器及版本.浏览器渲染引擎.浏 ...

  7. Struts2 实现文件上传和下载

    实现上传功能 Struts2实际上是使用的commons fileupload 组件,所以记得导包哦. 1.首先你应该有一个上传页面 <!-- file的name属性与action中的File类 ...

  8. R-Studio

    R-Studio是一个功能强大.节省成本的反删除和数据恢复软件系列.它采用独特的数据恢复新技术,为恢复FAT12/16/32.NTFS.NTFS5(由 Windows 2000/XP/2003/Vis ...

  9. Mysql复制表格

    1.复制表结构及数据到新表 CREATE TABLE 新表 as SELECT * FROM 旧表 不过这种方法的一个最不好的地方就是新表中没有了旧表的primary key.Extra(auto_i ...

  10. JDicom使用指南

    适用条件本指南用于使用JDicom进行环境模拟.产品调试. 一.安装JDicom运行JDicom安装程序之前,需安装JRE 1.3及以上版本.否则,弹出如下图所示报错 安装JRE 1.4:双击运行可执 ...