本章主要講如何在無root權限(包含無sudo權限)條件下於centos命令行中安裝nginx以及在大於1024的端口(這裏用8080)上運行。兩種方式,一是下載預編譯好的rpm包安裝(若是是經過下載rpm方式安裝,首先要找對應centos版本的rpm包),二是下載源碼後本身編譯(要依賴pcre庫、zlib庫等)。nginx
pcre 下載地址:www.pcre.org ,
zlib 下載地址:www.zlib.org ,
openssl 下載地址:www.openssl.orgapache
unzip pcre2-10.31.zip,解壓目錄爲:pcre2-10.31centos
而後進入到 cd pcre2-10.31,進行配置、編譯、安裝bash
配置ui
./configure或./configspa
編譯.net
make命令行
安裝code
make installip
備註:也可編譯安裝一塊兒進行 make && make install
解壓:
tar –zxvf openssl-1.1.1-pre7.tar.gz,解壓目錄爲:openssl-1.1.1-pre7
而後進入到 cd openssl-1.1.1-pre7,進行配置、編譯、安裝
配置
./configure或./config
編譯
make
安裝
make install
備註:也可編譯安裝一塊兒進行 make && make install
解壓:
tar –zxvf zlib-1.2.11.tar.gz,解壓目錄爲:zlib-1.2.11
而後進入到 cd zlib-1.2.11,進行配置、編譯、安裝
配置
./configure或./config
編譯
make
安裝
make install
備註:也可編譯安裝一塊兒進行 make && make install
解壓 nginx :
# 解壓 tar -zxvf nginx-1.15.0.tar.gz
安裝 nginx :
# 進入解壓目錄 cd ~/tools/nginx-1.15.0 # --with-pcre=後的路徑爲pcre的解壓後的源路徑 # --prefix=路徑爲nginx想要安裝到的目錄 ./configure --with-http_stub_status_module --prefix=/home/redhat/tools/nginx --with-pcre=/home/redhat/tools/pcre2-10.31
編譯與安裝 :
# 編譯 make # 安裝 make install # make && make install
提示:
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
緣由:
啓動不了的,由於非root用戶啓動不了1024如下端口
解決方案:
修改一下nginx.conf監聽端口爲1024以上端口,從新啓動nginx
提示:
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
緣由:
由於Nginx須要其餘第三方庫的支持,好比rewrite模塊須要pcre庫,ssl須要openssl庫等。
解決方案:
安裝所需的pcre(www.pcre.org),zlib(www.zlib.org),openssl(www.openssl.org)等。
提示:
make -f objs/Makefile make[1]: Entering directory `/home/redhat/tools/nginx' cd /home/redhat/tools/nginx/zzw_other/pcre-8.10 \ && if [ -f Makefile ]; then make distclean; fi \ && CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \ ./configure --disable-shared /bin/sh: line 2: ./configure: 沒有那個文件或目錄 make[1]: *** [/home/redhat/tools/nginx/zzw_other/pcre-8.10/Makefile] 錯誤 127 make[1]: Leaving directory `/home/redhat/tools/nginx' make: *** [build] 錯誤 2
緣由: --with-pcre=讓你設置到源碼目錄,而不是編譯安裝後的目錄。這點與apache的編譯還有點不一樣。用./configure -help 能夠看配置參數幫助 解決方案: 修改 --with-pcre=後的路徑爲pcre的解壓後的源路徑