CentOS 7.4 原始碼安裝 nginx 1.14
阿新 • • 發佈:2018-11-28
- 作業系統:CentOS 7.4
- nginx 版本:nginx-1.14.1
當前 Stable version 為 nginx-1.14.1 參考
與JRE、Tomcat不同,nginx並非解壓即可,還需要編譯、安裝。具體步驟如下:
一、準備環境
環境準備不完全會後面執行
./configure
對應報錯,本人嘗試了一下,比如缺少 3. zlib 函式庫 會報錯
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.
-
gcc(GNU編譯器套件)
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# rpm -q gcc gcc-4.8.5-16.el7.x86_64
若沒有輸出,則安裝
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y gcc
-
PCRE(Perl Compatible Regular Expressions) Perl庫
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# rpm -qa |grep pcre pcre-8.32-17.el7.x86_64 pcre-devel-8.32-17.el7.x86_64
缺少哪個要對應的安裝,比如缺少pcre-devel-8.32-17.el7.x86_64,則執行
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y pcre-devel
如果兩個都缺少,則執行
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y pcre pcre-devel
下面幾個依此類推
-
zlib 函式庫
[[email protected] ~]# rpm -qa |grep zlib zlib-devel-1.2.7-17.el7.x86_64 zlib-1.2.7-17.el7.x86_64
缺少哪個要對應的安裝
[[email protected] ~]# yum install -y zlib zlib-devel
-
openssl
[[email protected]xxxxxxxx ~]# rpm -qa |grep openssl openssl-libs-1.0.2k-12.el7.x86_64 openssl-devel-1.0.2k-12.el7.x86_64 openssl-1.0.2k-12.el7.x86_64
缺少哪個要對應的安裝
[[email protected] ~]# yum install -y openssl openssl-devel
二、解壓安裝
-
解壓
在nginx-1.14.1.tar.gz所在目錄,執行解壓命令,解壓目錄與安裝目錄是不同的,不用介意解壓位置
[[email protected] ~]# tar -zxvf nginx-1.14.1.tar.gz
-
./configure生成Makefile
如果不加
--with-http_stub_status_module
也是可以的,但配置ssl時會出錯,需要重新處理[[email protected] ~]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module checking for OS + Linux 3.10.0-693.2.2.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found Configuration summary ---------------- 此處省略一百多個checking for... ---------------- checking for PCRE JIT support ... found checking for zlib library ... found creating objs/Makefile Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/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"
如果結尾出現 ./configure: error: 要排查解決對應的原因,然後重新執行
./configure --prefix=/usr/local/nginx
-
make && make install
[[email protected] nginx-1.14.1]# make && make install
安裝結束後就可以看到 /usr/local/nginx 目錄,執行/usr/local/nginx/sbin/nginx啟動,就可以訪問了。
[[email protected] nginx]# /usr/local/nginx/sbin/nginx
後續的配置在下一篇部落格裡介紹