當前 Stable version 爲 nginx-1.14.1 參考html
與JRE、Tomcat不一樣,nginx並不是解壓便可,還須要編譯、安裝。具體步驟以下:nginx
1、準備環境ui
環境準備不徹底會後面執行
./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編譯器套件).net
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# rpm -q gcc gcc-4.8.5-16.el7.x86_64
若沒有輸出,則安裝code
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y gcc
PCRE(Perl Compatible Regular Expressions) Perl庫htm
[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,則執行blog
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y pcre-devel
若是兩個都缺乏,則執行ip
[root[@xxxxxxxx](https://my.oschina.net/u/1036001) ~]# yum install -y pcre pcre-devel
下面幾個依此類推ssl
zlib 函式庫
[root@xxxxxxxx ~]# rpm -qa |grep zlib zlib-devel-1.2.7-17.el7.x86_64 zlib-1.2.7-17.el7.x86_64
缺乏哪一個要對應的安裝
[root@xxxxxxxx ~]# yum install -y zlib zlib-devel
openssl
[root@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
缺乏哪一個要對應的安裝
[root@xxxxxxxx ~]# yum install -y openssl openssl-devel
2、解壓安裝
解壓
在nginx-1.14.1.tar.gz所在目錄,執行解壓命令,解壓目錄與安裝目錄是不一樣的,不用介意解壓位置
[root@xxxxxxxx ~]# tar -zxvf nginx-1.14.1.tar.gz
./configure生成Makefile
若是不加 --with-http_stub_status_module
也是能夠的,但配置ssl時會出錯,須要從新處理
[root@xxxxxxxx ~]# ./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
[root@xxxxxxxx nginx-1.14.1]# make && make install
安裝結束後就能夠看到 /usr/local/nginx 目錄,執行/usr/local/nginx/sbin/nginx啓動,就能夠訪問了。
[root@xxxxxxxx nginx]# /usr/local/nginx/sbin/nginx
後續的配置在下一篇博客裏介紹