天天看點

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的安裝結束。

繼續閱讀