Red Hat 6.3 下安装 nginx-1.7.4

1、安装准备

        在Redhat系统下,没有CentOS那样使用yum安装依赖包等,因此接下来主要记录一下如何一步一步安装Nginx相关的依赖库。html

下面就正式安装,因为安装Nginx须要依赖gcc-c++gccopenssl-develpcre-develzlib-devel等软件,通常状况下,咱们须要首先安装的是gcc-c++gcc,而后是pcre, zlib这两个库,最后到openssl-develnginx

1、安装gcc-c++gcc

        对于gccgcc-c++,参照前面一篇文章《Red Hat 6.3安装gcc gc++》的步骤,安装gcc gc++须要相应的rpm依赖包,这里就再也不详细说明了。c++


2、安装pcre

首先安装的是pcrepcre主要是为了nginxrewrite(重写)模块使用的。测试

进入到/usr/local目录spa

$	cd /usr/local

从网上下载最新版本的prce.net

$	wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

或者命令行

$	wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

解压文件code

$	tar -zxvf pcre-8.35.tar.gz

解压后生成pcre-8.35目录,进入到pcre-8.35目录安装htm

$	./configure
$	make
$	make install

这样就完成了pcre库的安装blog


3、安装zlib

zlib库主要是nginxgzip压缩模块使用

进入到/usr/local目录

$	cd  /usr/local

从网上下载最新版本的zlib

$	wget  http://zlib.net/zlib-1.2.8.tar.gz

解压文件

$	tar  -zxvf  zlib-1.2.8.tar.gz

解压后生成zlib-1.2.8目录

$	cd zlib-1.2.8

进入到zlib-1.2.8目录后执行命令行编译安装

$	./configure
$	make
$	make  install

这样就完成了zlib库的安装


4、安装openssl

进入到/usr/local目录

$	cd  /usr/local

从网上下载最新版本的openssl

$	wget  http://www.openssl.org/source/openssl-1.0.1i.tar.gz

解压文件

$	tar  -zxvf  openssl-1.0.1i.tar.gz

解压后生成openssl-1.0.1i目录

$	cd openssl-1.0.1i

进入到openssl-1.0.1i目录后执行命令行编译安装

$	./configure
$	make
$	make  install

这样就完成了openssl库的安装

2、安装nginx

首先进入/usr/local目录

$	cd /usr/local

从官网下载最新版的nginx

$	wget http://nginx.org/download/nginx-1.7.4.tar.gz

解压nginx压缩包

$	tar -zxvf nginx-1.7.4.tar.gz

会产生一个nginx-1.7.4 目录,这时进入nginx-1.7.4目录

$	cd  nginx-1.7.4

接下来安装,使用--prefix参数指定nginx安装的目录,make编译、make install安装

$	./configure  --prefix=/usr/local/nginx-1.7.4   #默认安装在/usr/local/nginx 
$	make
$	make install

若是没有报错,顺利完成后,最好看一下nginx的安装目录

$	whereis nginx

安装完毕后,进入安装后目录(/usr/local/nginx-1.7.4)即可以启动或中止它了

到此,使用安装nginx已经完成了,其实看看仍是蛮简单的。

特别提示:安装好以后,测试一下nginx配置没有错误,使用 -t 

$ 	/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

我这里发现了一个错误

./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

从错误能够看出是缺乏libpcre.so.1文件致使,因此,咱们进入系统根目录下/lib录中手动连接下

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

32位系统

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

再次启动nginx测试一下

$	/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfull

OK,测试经过,启动nginx

$	/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

查看一下nginx的进程

$	ps aux|grep nginx
或者
 $	ps -ef|grep nginx

看到有master processworker process进程,说明成功了