想自己安裝nginx,又不相用到root用戶。
非root用戶下(本文為用戶bdctool)來ngnix安裝,要依賴pcre庫、zlib庫等,
1、 下載依賴包:下載地址 pcre(www.pcre.org),zlib(www.zlib.org),openssl(www.openssl.org)
2、不用依賴包,先安裝一下試試
[bdctool@localhost setup]$ tar -zxvf nginx-1.12.2.tar.gz
[bdctool@localhost setup]$ ./configure --with-http_stub_status_module --prefix=/opt/aspire/product/bdctool/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.
3、還是安裝一下pcre吧
[bdctool@localhost setup]$ unzip pcre-8.10.zip
[bdctool@localhost setup]$ cd pcre-8.10
[bdctool@localhost pcre-8.10]$ ./configure --prefix=/opt/aspire/product/bdctool/nginx/zzw_other/pcre-8.10 (自定義目錄)
[bdctool@localhost pcre-8.10]$ make
[bdctool@localhost pcre-8.10]$ make install
4、再來安裝nginx,首先./configure
[bdctool@localhost nginx-1.12.2]$./configure --with-http_stub_status_module --prefix=/opt/aspire/product/bdctool/nginx --with-pcre=/opt/aspire/product/bdctool/nginx/zzw_other/pcre-8.10
注意:上面命令--prefix=路徑為nginx想要安裝到的目錄, --with-pcre=路徑為pcre安裝到的目錄。
.....................
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for zlib library ... found
creating objs/MakefileConfiguration summary
+ using PCRE library: /opt/aspire/product/bdctool/nginx/zzw_other/pcre-8.10
+ OpenSSL library is not used --- OpenSSL 可選
+ using system zlib library --- 其實是要依賴zlib包的,但系統已安裝,所以沒有額外安裝,如果系統沒安裝,要自行如pcre一樣安裝一下,並且在configure時加 --with-zlib=(自行安裝的zlib的目錄)nginx path prefix: "/opt/aspire/product/bdctool/nginx"
nginx binary file: "/opt/aspire/product/bdctool/nginx/sbin/nginx"
nginx modules path: "/opt/aspire/product/bdctool/nginx/modules"
nginx configuration prefix: "/opt/aspire/product/bdctool/nginx/conf"
nginx configuration file: "/opt/aspire/product/bdctool/nginx/conf/nginx.conf"
nginx pid file: "/opt/aspire/product/bdctool/nginx/logs/nginx.pid"
nginx error log file: "/opt/aspire/product/bdctool/nginx/logs/error.log"
nginx http access log file: "/opt/aspire/product/bdctool/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"沒什么大問題
4、再進行make
[bdctool@localhost nginx-1.12.2]$ make
make -f objs/Makefile
make[1]: Entering directory `/opt/aspire/product/bdctool/setup/nginx-1.12.2'
cd /opt/aspire/product/bdctool/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]: *** [/opt/aspire/product/bdctool/nginx/zzw_other/pcre-8.10/Makefile] 錯誤 127
make[1]: Leaving directory `/opt/aspire/product/bdctool/setup/nginx-1.12.2'
make: *** [build] 錯誤 2
出問題了,make報錯。
參考《http://www.cnblogs.com/yayagepei/articles/1884462.html》的解決方法 ,原來是--with-pcre=讓你設置到源碼目錄,而不是編譯安裝后的目錄;同樣的道理, --with-zlib=也是解壓后的源碼目錄,而不是zlib編譯安裝后的目錄!!!!。這點與apache的編譯還有點不同。用./configure -help 可以看配置參數幫助
5、修改 --with-pcre=后的路徑為pcre的解壓后的源路徑,重新./configure
[bdctool@localhost nginx-1.12.2]$./configure --with-http_stub_status_module --prefix=/opt/aspire/product/bdctool/nginx --with-pcre=/opt/aspire/product/bdctool/setup/pcre-8.10
6、重新make
[bdctool@localhost nginx-1.12.2]$ make
成功了,沒出問題
7、最后make install
[bdctool@localhost nginx-1.12.2]$ make install
完成,沒出問題
8、不改配置,試着啟動一下
[bdctool@localhost sbin]$ ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)啟動不了的,因為非root用戶啟動不了1024以下端口,具體解決方法見 http://www.cnblogs.com/zzw-zyba/p/8575428.html
9、修改一下nginx.conf監聽端口為1024以上端口,重新啟動nginx,成功。