版本
- ubunt16.04
- nginx-1.8.1
- gcc-4.8.4
- pcre-8.40
- zlib-1.2.11
- openssl-1.0.2n
前置環境配置
進入到 /usr/local 目錄下執行下面1 2 3 4,此處路徑與之後安裝nginx對應
1、gcc
源碼編譯依賴環境
apt-get install build-essential
apt-get install libtool
// gcc --version 查看gcc版本
// gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
2、PCRE ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx的http模塊使用pcre來解析正則表達式
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
make install
//查看pcre版本 pcre-config --version
3、zlib http://zlib.net
zlib庫提供了很多種壓縮和解壓縮的方式,nginx使用zlib對http包的內容進行gzip
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、penssl https://www.openssl.org/source/
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用.
nginx不僅支持http協議,還支持https(即在ssl協議上傳輸http)
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz
安裝步驟
一、源碼安裝
1.下載 nginx 壓縮包
wget https://nginx.org/download/nginx-1.8.1.tar.gz
2.解壓 nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
3.解壓後 我們通過 cd 命令進入到nginx-1.8.1文件夾下面
安裝nginx到 /usr/local/nginx目錄下
cd nginx-1.8.1
// 配置nginx
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/pcre-8.40 \
--with-zlib=/usr/local/zlib-1.2.11 \
--with-openssl=/usr/local/openssl-1.0.2n
// 編譯
make
// 安裝
make install
如果到此爲止沒有報錯,安裝成功
啓動nginx:
cd 到/usr/local/nginx
./nginx執行啓動文件
輸入你的服務器ip地址,會出現這樣的頁面
二、在線安裝
apt-get install nginx
啓動程序文件在/usr/sbin/nginx
日誌放在了/var/log/nginx中,分別是access.log和error.log
並已經在/etc/init.d/下創建了啓動腳本nginx
在線安裝啓動nginx
/etc/init.d/nginx start