CentOS7安裝Nginx及配置

Nginx是一款輕量級的網頁服務器、反向代理服務器。相較於Apache、lighttpd具有佔有內存少,穩定性高等優勢。

它最常的用途是提供反向代理服務。

TIPS:

  1. 在Centos下,yum源不提供nginx的安裝,可以通過切換yum源的方法獲取安裝。也可以通過直接下載安裝包的方法,**以下命令均需root權限執行**:

  2. 首先安裝必要的庫(nginx 中gzip模塊需要 zlib 庫,rewrite模塊需要 pcre 庫,ssl 功能需要openssl庫)。選定**/usr/local**爲安裝目錄,以下具體版本號根據實際改變。

安裝:

1.安裝nginx

cd /usr/local/

# 下載
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
 
# 解壓
tar -zxvf nginx-1.12.0.tar.gz
 
# 重命名
mv nginx-1.12.0 nginx

 

2.安裝gcc gcc-c++(如新環境,未安裝請先安裝)

yum install -y gcc gcc-c++

3.安裝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++

4.安裝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

5.安裝zlib庫存

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

配置nginx

cd /usr/local/nginx/

./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
(注: --with-http_ssl_module:這個不加後面在nginx.conf配置ssl:on後,啓動會報nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 異常)


make && make install


./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.33 --with-zlib=/usr/local/zlib-1.2.11 
(注:--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源碼路徑。--with-zlib=/usr/local/zlib-1.2.11 指的是zlib-1.2.11 的源碼路徑。)


make && make install

如果報錯:./configure: error: SSL modules require the OpenSSL library.

解決:yum -y install openssl openssl-devel

 

參考博客:https://www.cnblogs.com/jackyzm/p/9600738.html

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章