1. 程式人生 > >CentOS7.0安裝Nginx

CentOS7.0安裝Nginx

一、安裝準備

首先由於nginx的一些模組依賴一些lib庫,所以在安裝nginx之前,必須先安裝這些lib庫,這些依賴庫主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以執行如下命令安裝

[html] view plaincopy

  1. $   yum install gcc-c++  
  2. $   yum install pcre pcre-devel  
  3. $   yum install zlib zlib-devel  
  4. $   yum install openssl openssl--devel  

tips:Nginx官網提供了三個型別的版本

Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以說是開發版

Stable version:最新穩定版,生產環境上建議使用的版本

Legacy versions:遺留的老版本的穩定版

二、安裝Nginx

安裝之前,最好檢查一下是否已經安裝有nginx

[html] view plaincopy

  1. $   find -name nginx  

如果系統已經安裝了nginx,那麼就先解除安裝

[html] view plaincopy

  1. $   yum remove nginx  

首先進入/usr/local目錄

[html] view plaincopy

  1. $   cd /usr/local  

從官網下載最新版的nginx

[html] view plaincopy

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

解壓nginx壓縮包

[html] view plaincopy

  1. $   tar -zxvf nginx-1.7.4.tar.gz  

會產生一個nginx-1.7.4 目錄,這時進入nginx-1.7.4目錄

[html] view plaincopy

  1. $   cd  nginx-1.7.4  

接下來安裝,使用--prefix引數指定nginx安裝的目錄,make、make install安裝

[html] view plaincopy

  1. $   ./configure 
  2. $ make
  3. $   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

  1. $   whereis nginx  

/usr/local/nginx/sbin/nginx

安裝完畢後,進入安裝後目錄(/usr/local/nginx)便可以啟動或停止它了。

到此,使用CentOS安裝nginx已經完成了,其實看