天天看点

CentOS上nginx与tengine web服务器

公司这几天有一个新游戏要上架,需要一个web服务器。本打算使用apache,但是考虑到目前公司网站使用的也是nginx,还是选择nginx。

主要是考虑到两个方面:

一、 apache支持rpm及源码方式安装,而nginx从官网下载的只有源码方式安装。

二、 nginx以后是趋势,况且目前公司网站及论坛使用的也是nginx。

CentOS上nginx与tengine web服务器

我们也可以下载淘宝自己根据nginx定制的版本tengine,

CentOS上nginx与tengine web服务器

我们先按照nginx官网下载的版本,如下图:

CentOS上nginx与tengine web服务器

在安装nginx之前,我们需要安装相应的软件包。如下图:

CentOS上nginx与tengine web服务器

yum -y install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel

CentOS上nginx与tengine web服务器

相应的补丁包安装完毕后,我们就可以来安装nginx。首先解压nginx软件包,如下图:

wget http://nginx.org/download/nginx-1.7.2.tar.gz

CentOS上nginx与tengine web服务器

tar -xf nginx-1.7.2.tar.gz

然后进行编译,如下图:

CentOS上nginx与tengine web服务器

./configure –prefix=/usr/local/nginx,其实nginx安装的默认路径为/usr/local/nginx。所以在这里我们可以不设置nginx的安装路径直接使用./configure编译即可。

CentOS上nginx与tengine web服务器

根据上图信息,可以看到没有出错信息。下面我们直接,进行安装,如下图:

CentOS上nginx与tengine web服务器

make

CentOS上nginx与tengine web服务器

make install

CentOS上nginx与tengine web服务器

到此nginx安装完毕,下面我们来启动nginx。看看实际的效果:

CentOS上nginx与tengine web服务器

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

netstat –tunlp

CentOS上nginx与tengine web服务器

查看已经安装的模块:

CentOS上nginx与tengine web服务器

./sbin/nginx –v

以上安装的是nginx官网的,可以看到基本没有安装其他模块。

下面安装淘宝tengine nginx定制版本,如下图:

 wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz

CentOS上nginx与tengine web服务器

如果在新的服务器上安装的话,还是需要安装相应相应的人家包:

编译tengine,为了和前边安装的nginx进行区别。现在把tengine安装到/usr/local/ tengine这个目录下,如下图:

CentOS上nginx与tengine web服务器
CentOS上nginx与tengine web服务器

./configure –prefix=/usr/local/tengine

然后进行安装:

CentOS上nginx与tengine web服务器
CentOS上nginx与tengine web服务器

make && make install

好了tengine已经安装完毕,下面我们来启动tengine。但是考虑到前边,已经安装过nginx。所以我们先修改tengine的端口号,先使用81端口。如下图:

CentOS上nginx与tengine web服务器
CentOS上nginx与tengine web服务器

启动tengine,如下图:

CentOS上nginx与tengine web服务器
CentOS上nginx与tengine web服务器

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

可以看到tengine已经正常启动。

下面看看已经安装的模块,如下图:

CentOS上nginx与tengine web服务器

所以在按照nginx时,建议使用淘宝的tengine。至此nginx的安装结束。

继续阅读