CentOS7.0安裝Nginx
一、安裝準備
首先由於nginx的一些模組依賴一些lib庫,所以在安裝nginx之前,必須先安裝這些lib庫,這些依賴庫主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以執行如下命令安裝
[html] view plaincopy
- $ yum install gcc-c++
- $ yum install pcre pcre-devel
- $ yum install zlib zlib-devel
- $ yum install openssl openssl--devel
tips:Nginx官網提供了三個型別的版本
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以說是開發版
Stable version:最新穩定版,生產環境上建議使用的版本
Legacy versions:遺留的老版本的穩定版
二、安裝Nginx
安裝之前,最好檢查一下是否已經安裝有nginx
[html] view plaincopy
- $ find -name nginx
如果系統已經安裝了nginx,那麼就先解除安裝
[html] view plaincopy
- $ yum remove nginx
首先進入/usr/local目錄
[html] view plaincopy
- $ cd /usr/local
從官網下載最新版的nginx
[html] view plaincopy
- $ wget http://nginx.org/download/nginx-1.7.4.tar.gz
解壓nginx壓縮包
[html] view plaincopy
- $ tar -zxvf nginx-1.7.4.tar.gz
會產生一個nginx-1.7.4 目錄,這時進入nginx-1.7.4目錄
[html] view plaincopy
- $ cd nginx-1.7.4
接下來安裝,使用--prefix引數指定nginx安裝的目錄,make、make install安裝
[html] view plaincopy
- $ ./configure
- $ make
- $ make install
安裝Nginx時報錯
./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解決辦法:
yum -y install openssl openssl-devel
總結:
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install
一切搞定
如果沒有報錯,順利完成後,最好看一下nginx的安裝目錄
[html] view plaincopy
- $ whereis nginx
/usr/local/nginx/sbin/nginx
安裝完畢後,進入安裝後目錄(/usr/local/nginx)便可以啟動或停止它了。
到此,使用CentOS安裝nginx已經完成了,其實看