author:咔咔
1.在第一次安裝nginx時,使用make編譯和make install安裝時會安裝不到usr/local/下,這個時候在編譯一次即可
2.在./configure時,有的夥伴沒有安裝基礎包出現的問題ivalid c++ compiler or c++ compiler flags,這個需要yum install -y gcc gcc-c++即可
3.主機ping不同虛拟機問題在其他文章寫,關閉虛拟機防火牆即可
nginx最終的安裝目錄會在/usr/local/ngixn下
安裝基礎包
一、安裝nginx依賴的軟體nginx官網介紹配置安裝:http://nginx.org/en/docs/configure.html
nginx是C寫的,需要用GCC編譯;nginx中的rewrite module需要PCRE;nginx中的gzip module需要zlib;nginx中的HTTP SSL module需要OpenSSL。
已安裝的GCC版本資訊如下:
zlib下載下傳官網:http://www.zlib.net/ 1、zlib源碼安裝:
下載下傳zlib最新版本1.2.11源碼:
<col>
1
<code>[root@localhost plu]# wget http:</code><code>//prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz</code>
解壓并進入zlib代碼根目錄:
2
<code>tar zxvf zlib-1.2.11.tar.gz</code>
<code>cd zlib-1.2.11</code>
配置、編譯、安裝:
3
<code>[root@localhost zlib-1.2.11]# ./configure</code>
<code>[root@localhost zlib-1.2.11]# make</code>
<code>[root@localhost zlib-1.2.11]# make install</code>
2、pcre源碼安裝:
PCRE官網:http://www.pcre.org/
下載下傳PCRE最新版本8.42源碼:
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
<code>[root@localhost ~]# tar zxvf pcre-8.42.tar.gz</code>
<code>[root@localhost ~]# cd pcre-8.42</code>
解壓并進入PCRE代碼根目錄:
<code>[root@localhost pcre-8.42]# ./configure</code>
<code>[root@localhost pcre-8.42]# make</code>
<code>[root@localhost pcre-8.42]# make install</code>
檢視版本
<code>[root@localhost pcre-8.42]# pcre-config --version</code>
<code>8.42</code>
3、OpenSSL源碼安裝:
OpenSSL官網:https://www.openssl.org/
下載下傳OpenSSL版本1.0.2o源碼:
<code>wget https:</code><code>//www.openssl.org/source/openssl-1.0.2o.tar.gz</code>
解壓并進入openssl代碼根目錄:
<code>[root@localhost ~]# tar zxvf openssl-1.0.2o.tar.gz</code>
<code>[root@localhost ~]# cd openssl-1.0.2o</code>
<code>[root@localhost openssl-1.0.2o]# ./config</code>
<code>[root@localhost openssl-1.0.2o]# make</code>
<code>[root@localhost openssl-1.0.2o]# make install</code>
nginx最新穩定版本1.14.0
<code>wget http:</code><code>//nginx.org/download/nginx-1.14.0.tar.gz</code>
解壓并進入nginx代碼根目錄:
<code>[root@localhost ~]# tar zxvf nginx-1.14.0.tar.gz</code>
<code>[root@localhost ~]# cd nginx-1.14.0</code>
配置:
<code>[root@localhost nginx-1.14.0]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2o</code>
編譯安裝:
<code>[root@localhost nginx-1.14.0]# make</code>
<code>[root@localhost nginx-1.14.0]# make install</code>
檢查nginx.conf配置正确性:
<code>[root@localhost nginx-1.14.0]# /usr/local/nginx/sbin/nginx -t </code>
<code>nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax </code><code>is</code> <code>ok</code>
<code>nginx: configuration file /usr/local/nginx/conf/nginx.conf test </code><code>is</code> <code>successful</code>
啟動服務
<code>[root@localhost nginx-1.14.0]# /usr/local/nginx/sbin/nginx</code>
停止服務
<code>/usr/local/nginx/sbin/nginx -s stop </code>
指令相關詳見官網:http://nginx.org/en/docs/beginners_guide.html
設定開機自啟動
<code>[root@localhost ~]# chmod 755 /etc/rc.d/rc.local</code>
<code>[root@localhost ~]# vim /etc/rc.d/rc.local</code>