1. 安装编译器

yum install -y gcc gcc-c++ make autoconf

2. 安装pcre库

Pcre全称(Perl Compatible Regular Expressions),中文“perl兼容正则表达式”,官方站点
http://www.pcre.org/ ,安装pcre库是为了使Nginx支持具备URI重写功能的Rewrite模块,
如果不安装pcre库,则Nginx无法使用Rewrite模块功能,Nginx的Rewrite模块功能几乎是企业
应用必须。安装pcre库的过程如下。

安装命令:
[root@web01 ~]# yum install pcre pcre-devel -y

yum安装操作后检查安装结果:
[root@web01 ~]# rpm -qa pcre pcre-devel
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64
也可采用编译方法安装pcre,比较复杂不推荐。

3. 安装openssl

为了将来方便,我们也需要把openssl安装上,安装方法如下。
安装命令:
[root@web01 ~]# yum install openssl-devel -y

yum安装后检查安装结果:
[root@web01 ~]# rpm -qa openssl-devel
openssl-devel-1.0.1e-48.el6_8.3.x86_64

4. 下载Nginx软件

[root@web01 nginx-1.6.3]# wget http://nginx.org/download/nginx-1.6.3.tar.gz

创建Nginx进程用户
[root@web01 nginx-1.6.3]# useradd nginx -M -s /sbin/nologin
[root@web01 nginx-1.6.3]# id nginx
uid=502(nginx) gid=502(nginx) groups=502(nginx)

5. 解压并编译Nginx

[root@web01 tools]# tar xf nginx-1.6.3.tar.gz
[root@web01 tools]# cd nginx-1.6.3
[root@web01 nginx-1.6.3]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
预编译:
[root@web01 nginx-1.6.3]# ./configure --prefix=/app/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre
编译:
make
安装:
make install

创建软连接:
ln -s /app/nginx-1.6.3/ /app/nginx

6. 编译参数说明:

—prefix=PATH set installation prefix #←设置安装路径
—user=USER set non-privileged user for worker processes #←进程用户
—group=GROUP set non-privileged group forworker processes #←进程用户组
—with-http_spdy_module enable ngx_http_spdy_module #←激活spdy模块
—with-http_ssl_module enable ngx_http_ssl_module #←激活ssl功能
—with-http_stub_status_module enable ngx_http_stub_status_module #←激活状态信息
—with-pcre force PCRE library usage #←激活Rewrite模块

7. 启动Nginx

[root@web01 nginx-1.6.3]# /app/nginx/sbin/nginx
检查是否启动成功:
[root@web01 nginx-1.6.3]# netstat -alntup|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 5682/nginx
[root@web01 nginx-1.6.3]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 5682 root 6u IPv4 18001 0t0 TCP
:http (LISTEN)
nginx 5683 nginx 6u IPv4 18001 0t0 TCP *:http (LISTEN)

启动成功后通过浏览器应该能看到如下的界面信息:
安装Nginx - 图1