-
在Centos下,yum源不提供nginx的安裝,可以通過切換yum源的方法獲取安裝。也可以通過直接下載安裝包的方法,**以下命令均需root權限執行**:
-
首先安裝必要的庫(nginx 中gzip模塊需要 zlib 庫,rewrite模塊需要 pcre 庫,ssl 功能需要openssl庫)。選定**/usr/local**爲安裝目錄,以下具體版本號根據實際改變。
1.安裝gcc gcc-c++(如新環境,未安裝請先安裝)
-
yum install -y gcc gcc-c++
-
yum -y install wget
3. yum install -y tar
2. 安裝PCRE庫
-
cd /usr/local/
-
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
-
tar -zxvf pcre-8.33.tar.gz
-
cd pcre-8.33
-
./configure
-
make && make install
-
如報錯:configure: error: You need a C++ compiler for C++ support
-
解決:yum install -y gcc gcc-c++
3.安裝SSL庫
-
$ cd /usr/local/
-
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
-
$ tar -zxvf openssl-1.0.1j.tar.gz
-
$ cd openssl-1.0.1j
-
$ ./config
-
$ make && make install
- cd /usr/local/
- wget http://zlib.net/zlib-1.2.11.tar.gz
- tar -zxvf zlib-1.2.11.tar.gz
- cd zlib-1.2.11/
- ./configure
- make && make install
4.安裝nginx
-
$ cd /usr/local/
-
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
-
$ tar -zxvf nginx-1.8.0.tar.gz
-
$ cd nginx-1.8.0
-
$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
時提示以下錯誤:
./configure: error: SSL modules require the OpenSSL library.
支持此命令:
yum -y install openssl openssl-devel
-
(注: --with-http_ssl_module:這個不加後面在nginx.conf配置ssl:on後,啓動會報nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 異常)
-
$ make && make install
-
-
報錯:./configure: error: the HTTP gzip module requires the zlib library
-
在–prefix後面接以下命令:
-
--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源碼路徑。--with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源碼路徑。
-
查看Nginx 是否正常
curl http://localhost
-