安裝說明
系統環境:CentOS6.6
軟件:nginx-1.10.3.tar.gz
其他所需軟件:openssl-1.1.0e.tar.gz、pcre-8.35.tar.gz、zlib-1.2.11.tar.gz
安裝方式:源碼編譯安裝
安裝位置:/usr/local/nginx
openssl下載地址:http://www.openssl.org/
nginx下載地址:http://nginx.org/en/download.html
pcre下載地址:https://sourceforge.net/projects/pcre/files/pcre/8.35/
zlib下載地址:http://www.zlib.net/zlib-1.2.11.tar.gz
安裝前提
在安裝nginx前,需要確保系統安裝了g++、gcc
步驟如下:
1.安裝openssl軟件
#進入安裝目錄 cd /usr/local/ #解壓 tar -zxv -f openssl-1.1.0e.tar.gz #進入源碼目錄 cd openssl-1.1.0e #配置 ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/conf #編譯安裝 make && make install #檢驗安裝 /usr/local/openssl/bin/openssl version -a errors: [root@bogon openssl-1.1.0e]# /usr/local/openssl/bin/openssl -version -a /usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory 解決方法: 做一個軟連接
假如你的libssl.so.1.1 文件在/usr/local/openssl/lib/下面,可以這樣做
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
繼續運行
/usr/local/openssl/bin/openssl -version -a 輸入如下: OpenSSL 1.1.0e 16 Feb 2017 built on: reproducible build, date unspecified platform: linux-x86_64 compiler: gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/openssl/conf\"" -DENGINESDIR="\"/usr/local/openssl/lib/engines-1.1\"" -Wa,--noexecstack OPENSSLDIR: "/usr/local/openssl/conf" ENGINESDIR: "/usr/local/openssl/lib/engines-1.1" 安裝成功!!!
2.安裝pcre軟件
#進入安裝目錄
cd /usr/local/
#解壓
tar -zxv -f pcre-8.35.tar.gz
#進入源碼目錄cd pcre-8.35
#執行配置./configure --prefix=/usr/local/pcre/
#編譯安裝make && make install
3.安裝zlib軟件
#進入安裝目錄 cd /usr/local/ #解壓 tar -zxv -f zlib-1.2.11.tar.gz #進入源碼目錄 cd zlib-1.2.11 #配置 ./configure --prefix=/usr/local/zlib/ # 編譯安裝 make && make install
4. 安裝nginx軟件
#---------------------------------------------------------------- # 安裝前提: openssl、pcre、zlib # 注意: # 不使用自已安裝的openssl的時候,要安裝openssl-devel,否則編譯不通過。 # yum install openssl-devel 此時參數可以不使用--with-open_ssl=/usr/local/openssl-1.0.1g #---------------------------------------------------------------- #添加www用戶和組 groupadd www useradd -g www www #創建網站根目錄 mkdir -p /var/www/root/ chmod -R 775 /var/www/root/ #進入安裝目錄 cd /usr/local #解壓 tar -zxvf nginx-1.10.3.tar.gz #進入安裝目錄 cd nginx-1.10.3 #配置(使用openssl、pcre、zlib的源碼路徑) ./configure \ --user=www \ --group=www \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-openssl=/usr/local/software/openssl-1.1.0e \ --with-pcre=/usr/local/software/pcre-8.35 \ --with-zlib=/usr/local/software/zlib-1.2.11 \ --with-http_stub_status_module \ --with-threads #編譯安裝 make && make install #驗證 /usr/local/nginx/sbin/nginx -V 輸入如下: nginx version: nginx/1.10.3 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.1.0e 16 Feb 2017 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/software/openssl-1.1.0e --with-pcre=/usr/local/software/pcre-8.35 --with-zlib=/usr/local/software/zlib-1.2.11 --with-http_stub_status_module --with-threads 安裝完成!!!
修改配置文件
vi /usr/local/nginx/conf/nginx.conf
啓動、重啓
#啓動: /usr/local/nginx/sbin/nginx #重啓 /usr/local/nginx/sbin/nginx -s reload
停止
#查詢nginx主進程號 |
測試
#測試端口
netstat –na|grep 80
#瀏覽器中測試
http://ip:80