Linux /centos7源碼編譯安裝Nginx

1、下載或上傳nginx安裝包
我這邊使用wget命令直接在centos7上下載,上傳安裝包的可以忽略直接下一步

[root@localhost ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
-bash: wget: 未找到命令

提示未找到wget命令,安裝wget命令

[root@localhost ~]# yum install -y wget
  已加載插件:fastestmirror
base                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                               | 3.4 kB  00:00:00     
updates                                                                                              | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                        | 166 kB  00:00:01     
(2/4): updates/7/x86_64/primary_db                                                                   | 7.4 MB  00:00:01     
(3/4): extras/7/x86_64/primary_db                                                                    | 215 kB  00:00:02     
(4/4): base/7/x86_64/primary_db                                                                      | 6.0 MB  00:00:04     
Determining fastest mirrors
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 wget.x86_64.0.1.14-18.el7_6.1 將被 安裝
--> 解決依賴關係完成

依賴關係解決

============================================================================================================================
 Package                  架構                       版本                                 源                           大小
============================================================================================================================
正在安裝:
 wget                     x86_64                     1.14-18.el7_6.1                      updates                     547 k

事務概要
============================================================================================================================
安裝  1 軟件包

總下載量:547 k
安裝大小:2.0 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/updates/packages/wget-1.14-18.el7_6.1.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
wget-1.14-18.el7_6.1.x86_64.rpm 的公鑰尚未安裝
wget-1.14-18.el7_6.1.x86_64.rpm                                                                      | 547 kB  00:00:00     
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 檢索密鑰
導入 GPG key 0xF4A80EB5:
 用戶ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 指紋       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 軟件包     : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
 來自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : wget-1.14-18.el7_6.1.x86_64                                                                             1/1 
  驗證中      : wget-1.14-18.el7_6.1.x86_64                                                                             1/1 

已安裝:
  wget.x86_64 0:1.14-18.el7_6.1                                                                                             

完畢!

安裝完成wget命令後再次執行第一步操作下載nginx

 [root@localhost ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

--2019-08-26 10:07:11--  http://nginx.org/download/nginx-1.16.1.tar.gz
正在解析主機 nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
正在連接 nginx.org (nginx.org)|95.211.80.227|:80... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:1032630 (1008K) [application/octet-stream]
正在保存至: “nginx-1.16.1.tar.gz”

100%[==================================================================================>] 1,032,630    123KB/s 用時 9.6s   

2019-08-26 10:07:21 (105 KB/s) - 已保存 “nginx-1.16.1.tar.gz” [1032630/1032630])

下載完成,ls命令查看下載的軟件包

[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.16.1.tar.gz

2、解壓軟件包,ls命令查看nginx目錄,並進入nginx目錄

[root@localhost ~]# tar xzf nginx-1.16.1.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.16.1  nginx-1.16.1.tar.gz
[root@localhost ~]# cd nginx-1.16.1
[root@localhost nginx-1.16.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

進入nginx目錄後預編譯,提示錯誤,缺少C編譯器

[root@localhost nginx-1.16.1]# ./configure
checking for OS
 + Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

 安裝c編譯器

[root@localhost nginx-1.16.1]# yum install -y gcc-c++
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 gcc-c++.x86_64.0.4.8.5-36.el7_6.2 將被 安裝
--> 正在處理依賴關係 libstdc++-devel = 4.8.5-36.el7_6.2,它被軟件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 libstdc++ = 4.8.5-36.el7_6.2,它被軟件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 gcc = 4.8.5-36.el7_6.2,它被軟件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 libmpfr.so.4()(64bit),它被軟件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 libmpc.so.3()(64bit),它被軟件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 需要
--> 正在檢查事務
---> 軟件包 gcc.x86_64.0.4.8.5-36.el7_6.2 將被 安裝
--> 正在處理依賴關係 libgomp = 4.8.5-36.el7_6.2,它被軟件包 gcc-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 cpp = 4.8.5-36.el7_6.2,它被軟件包 gcc-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 libgcc >= 4.8.5-36.el7_6.2,它被軟件包 gcc-4.8.5-36.el7_6.2.x86_64 需要
--> 正在處理依賴關係 glibc-devel >= 2.2.90-12,它被軟件包 gcc-4.8.5-36.el7_6.2.x86_64 需要
---> 軟件包 libmpc.x86_64.0.1.0.1-3.el7 將被 安裝
---> 軟件包 libstdc++.x86_64.0.4.8.5-16.el7 將被 升級
---> 軟件包 libstdc++.x86_64.0.4.8.5-36.el7_6.2 將被 更新
---> 軟件包 libstdc++-devel.x86_64.0.4.8.5-36.el7_6.2 將被 安裝
---> 軟件包 mpfr.x86_64.0.3.1.1-4.el7 將被 安裝
--> 正在檢查事務
---> 軟件包 cpp.x86_64.0.4.8.5-36.el7_6.2 將被 安裝
---> 軟件包 glibc-devel.x86_64.0.2.17-260.el7_6.6 將被 安裝
--> 正在處理依賴關係 glibc-headers = 2.17-260.el7_6.6,它被軟件包 glibc-devel-2.17-260.el7_6.6.x86_64 需要
--> 正在處理依賴關係 glibc = 2.17-260.el7_6.6,它被軟件包 glibc-devel-2.17-260.el7_6.6.x86_64 需要
--> 正在處理依賴關係 glibc-headers,它被軟件包 glibc-devel-2.17-260.el7_6.6.x86_64 需要
---> 軟件包 libgcc.x86_64.0.4.8.5-16.el7 將被 升級
---> 軟件包 libgcc.x86_64.0.4.8.5-36.el7_6.2 將被 更新
---> 軟件包 libgomp.x86_64.0.4.8.5-16.el7 將被 升級
---> 軟件包 libgomp.x86_64.0.4.8.5-36.el7_6.2 將被 更新
--> 正在檢查事務
---> 軟件包 glibc.x86_64.0.2.17-196.el7 將被 升級
--> 正在處理依賴關係 glibc = 2.17-196.el7,它被軟件包 glibc-common-2.17-196.el7.x86_64 需要
---> 軟件包 glibc.x86_64.0.2.17-260.el7_6.6 將被 更新
---> 軟件包 glibc-headers.x86_64.0.2.17-260.el7_6.6 將被 安裝
--> 正在處理依賴關係 kernel-headers >= 2.2.1,它被軟件包 glibc-headers-2.17-260.el7_6.6.x86_64 需要
--> 正在處理依賴關係 kernel-headers,它被軟件包 glibc-headers-2.17-260.el7_6.6.x86_64 需要
--> 正在檢查事務
---> 軟件包 glibc-common.x86_64.0.2.17-196.el7 將被 升級
---> 軟件包 glibc-common.x86_64.0.2.17-260.el7_6.6 將被 更新
---> 軟件包 kernel-headers.x86_64.0.3.10.0-957.27.2.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

============================================================================================================================
 Package                         架構                   版本                                  源                       大小
============================================================================================================================
正在安裝:
 gcc-c++                         x86_64                 4.8.5-36.el7_6.2                      updates                 7.2 M
爲依賴而安裝:
 cpp                             x86_64                 4.8.5-36.el7_6.2                      updates                 5.9 M
 gcc                             x86_64                 4.8.5-36.el7_6.2                      updates                  16 M
 glibc-devel                     x86_64                 2.17-260.el7_6.6                      updates                 1.1 M
 glibc-headers                   x86_64                 2.17-260.el7_6.6                      updates                 684 k
 kernel-headers                  x86_64                 3.10.0-957.27.2.el7                   updates                 8.0 M
 libmpc                          x86_64                 1.0.1-3.el7                           base                     51 k
 libstdc++-devel                 x86_64                 4.8.5-36.el7_6.2                      updates                 1.5 M
 mpfr                            x86_64                 3.1.1-4.el7                           base                    203 k
爲依賴而更新:
 glibc                           x86_64                 2.17-260.el7_6.6                      updates                 3.7 M
 glibc-common                    x86_64                 2.17-260.el7_6.6                      updates                  12 M
 libgcc                          x86_64                 4.8.5-36.el7_6.2                      updates                 102 k
 libgomp                         x86_64                 4.8.5-36.el7_6.2                      updates                 158 k
 libstdc++                       x86_64                 4.8.5-36.el7_6.2                      updates                 305 k

事務概要
============================================================================================================================
安裝  1 軟件包 (+8 依賴軟件包)
升級           ( 5 依賴軟件包)

總下載量:57 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/14): gcc-4.8.5-36.el7_6.2.x86_64.rpm                                                              |  16 MB  00:00:02     
(2/14): gcc-c++-4.8.5-36.el7_6.2.x86_64.rpm                                                          | 7.2 MB  00:00:01     
(3/14): glibc-2.17-260.el7_6.6.x86_64.rpm                                                            | 3.7 MB  00:00:00     
(4/14): glibc-common-2.17-260.el7_6.6.x86_64.rpm                                                     |  12 MB  00:00:01     
(5/14): glibc-devel-2.17-260.el7_6.6.x86_64.rpm                                                      | 1.1 MB  00:00:00     
(6/14): glibc-headers-2.17-260.el7_6.6.x86_64.rpm                                                    | 684 kB  00:00:00     
(7/14): kernel-headers-3.10.0-957.27.2.el7.x86_64.rpm                                                | 8.0 MB  00:00:01     
(8/14): libgcc-4.8.5-36.el7_6.2.x86_64.rpm                                                           | 102 kB  00:00:02     
(9/14): libgomp-4.8.5-36.el7_6.2.x86_64.rpm                                                          | 158 kB  00:00:00     
(10/14): libmpc-1.0.1-3.el7.x86_64.rpm                                                               |  51 kB  00:00:00     
(11/14): libstdc++-4.8.5-36.el7_6.2.x86_64.rpm                                                       | 305 kB  00:00:00     
(12/14): libstdc++-devel-4.8.5-36.el7_6.2.x86_64.rpm                                                 | 1.5 MB  00:00:00     
cpp-4.8.5-36.el7_6.2.x86_64.rp FAILED                                          
http://centos.ustc.edu.cn/centos/7.6.1810/updates/x86_64/Packages/cpp-4.8.5-36.el7_6.2.x86_64.rpm: [Errno 12] Timeout on http://centos.ustc.edu.cn/centos/7.6.1810/updates/x86_64/Packages/cpp-4.8.5-36.el7_6.2.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
(13/14): cpp-4.8.5-36.el7_6.2.x86_64.rpm                                                             | 5.9 MB  00:00:04     
mpfr-3.1.1-4.el7.x86_64.rpm    FAILED                                          
http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/mpfr-3.1.1-4.el7.x86_64.rpm: [Errno 12] Timeout on http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/mpfr-3.1.1-4.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
(14/14): mpfr-3.1.1-4.el7.x86_64.rpm                                                                 | 203 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------
總計                                                                                        1.4 MB/s |  57 MB  00:00:41     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : libgcc-4.8.5-36.el7_6.2.x86_64                                                                         1/19 
  正在更新    : glibc-common-2.17-260.el7_6.6.x86_64                                                                   2/19 
  正在更新    : glibc-2.17-260.el7_6.6.x86_64                                                                          3/19 
  正在安裝    : mpfr-3.1.1-4.el7.x86_64                                                                                4/19 
  正在安裝    : libmpc-1.0.1-3.el7.x86_64                                                                              5/19 
  正在更新    : libstdc++-4.8.5-36.el7_6.2.x86_64                                                                      6/19 
  正在安裝    : libstdc++-devel-4.8.5-36.el7_6.2.x86_64                                                                7/19 
  正在安裝    : cpp-4.8.5-36.el7_6.2.x86_64                                                                            8/19 
  正在更新    : libgomp-4.8.5-36.el7_6.2.x86_64                                                                        9/19 
  正在安裝    : kernel-headers-3.10.0-957.27.2.el7.x86_64                                                             10/19 
  正在安裝    : glibc-headers-2.17-260.el7_6.6.x86_64                                                                 11/19 
  正在安裝    : glibc-devel-2.17-260.el7_6.6.x86_64                                                                   12/19 
  正在安裝    : gcc-4.8.5-36.el7_6.2.x86_64                                                                           13/19 
  正在安裝    : gcc-c++-4.8.5-36.el7_6.2.x86_64                                                                       14/19 
  清理        : libstdc++-4.8.5-16.el7.x86_64                                                                         15/19 
  清理        : libgomp-4.8.5-16.el7.x86_64                                                                           16/19 
  清理        : glibc-common-2.17-196.el7.x86_64                                                                      17/19 
  清理        : glibc-2.17-196.el7.x86_64                                                                             18/19 
  清理        : libgcc-4.8.5-16.el7.x86_64                                                                            19/19 
  驗證中      : glibc-devel-2.17-260.el7_6.6.x86_64                                                                    1/19 
  驗證中      : gcc-c++-4.8.5-36.el7_6.2.x86_64                                                                        2/19 
  驗證中      : mpfr-3.1.1-4.el7.x86_64                                                                                3/19 
  驗證中      : glibc-2.17-260.el7_6.6.x86_64                                                                          4/19 
  驗證中      : kernel-headers-3.10.0-957.27.2.el7.x86_64                                                              5/19 
  驗證中      : libgcc-4.8.5-36.el7_6.2.x86_64                                                                         6/19 
  驗證中      : libgomp-4.8.5-36.el7_6.2.x86_64                                                                        7/19 
  驗證中      : libmpc-1.0.1-3.el7.x86_64                                                                              8/19 
  驗證中      : cpp-4.8.5-36.el7_6.2.x86_64                                                                            9/19 
  驗證中      : gcc-4.8.5-36.el7_6.2.x86_64                                                                           10/19 
  驗證中      : glibc-headers-2.17-260.el7_6.6.x86_64                                                                 11/19 
  驗證中      : libstdc++-devel-4.8.5-36.el7_6.2.x86_64                                                               12/19 
  驗證中      : glibc-common-2.17-260.el7_6.6.x86_64                                                                  13/19 
  驗證中      : libstdc++-4.8.5-36.el7_6.2.x86_64                                                                     14/19 
  驗證中      : libgomp-4.8.5-16.el7.x86_64                                                                           15/19 
  驗證中      : libgcc-4.8.5-16.el7.x86_64                                                                            16/19 
  驗證中      : glibc-2.17-196.el7.x86_64                                                                             17/19 
  驗證中      : libstdc++-4.8.5-16.el7.x86_64                                                                         18/19 
  驗證中      : glibc-common-2.17-196.el7.x86_64                                                                      19/19 

已安裝:
  gcc-c++.x86_64 0:4.8.5-36.el7_6.2                                                                                         

作爲依賴被安裝:
  cpp.x86_64 0:4.8.5-36.el7_6.2                                  gcc.x86_64 0:4.8.5-36.el7_6.2                             
  glibc-devel.x86_64 0:2.17-260.el7_6.6                          glibc-headers.x86_64 0:2.17-260.el7_6.6                   
  kernel-headers.x86_64 0:3.10.0-957.27.2.el7                    libmpc.x86_64 0:1.0.1-3.el7                               
  libstdc++-devel.x86_64 0:4.8.5-36.el7_6.2                      mpfr.x86_64 0:3.1.1-4.el7                                 

作爲依賴被升級:
  glibc.x86_64 0:2.17-260.el7_6.6        glibc-common.x86_64 0:2.17-260.el7_6.6      libgcc.x86_64 0:4.8.5-36.el7_6.2     
  libgomp.x86_64 0:4.8.5-36.el7_6.2      libstdc++.x86_64 0:4.8.5-36.el7_6.2        

完畢!

 c編譯器安裝完成,再次進行預編譯,錯誤提示缺少依賴庫pcre

[root@localhost nginx-1.16.1]# ./configure
checking for OS
 + Linux 3.10.0-693.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-36) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./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.

安裝依賴庫pcre

[root@localhost nginx-1.16.1]# yum install -y pcre-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 pcre-devel.x86_64.0.8.32-17.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

============================================================================================================================
 Package                        架構                       版本                              源                        大小
============================================================================================================================
正在安裝:
 pcre-devel                     x86_64                     8.32-17.el7                       base                     480 k

事務概要
============================================================================================================================
安裝  1 軟件包

總下載量:480 k
安裝大小:1.4 M
Downloading packages:
pcre-devel-8.32-17.el7.x86_64.rpm                                                                    | 480 kB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : pcre-devel-8.32-17.el7.x86_64                                                                           1/1 
  驗證中      : pcre-devel-8.32-17.el7.x86_64                                                                           1/1 

已安裝:
  pcre-devel.x86_64 0:8.32-17.el7                                                                                           

完畢!

 pcre庫組件安裝完成,再次進行預編譯,錯誤提示缺少依賴庫zlib

[root@localhost nginx-1.16.1]# ./configure
checking for OS
 + Linux 3.10.0-693.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-36) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... not found

./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.

安裝依賴庫zlib

[root@localhost nginx-1.16.1]# yum install -y zlib-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 zlib-devel.x86_64.0.1.2.7-18.el7 將被 安裝
--> 正在處理依賴關係 zlib = 1.2.7-18.el7,它被軟件包 zlib-devel-1.2.7-18.el7.x86_64 需要
--> 正在檢查事務
---> 軟件包 zlib.x86_64.0.1.2.7-17.el7 將被 升級
---> 軟件包 zlib.x86_64.0.1.2.7-18.el7 將被 更新
--> 解決依賴關係完成

依賴關係解決

============================================================================================================================
 Package                        架構                       版本                              源                        大小
============================================================================================================================
正在安裝:
 zlib-devel                     x86_64                     1.2.7-18.el7                      base                      50 k
爲依賴而更新:
 zlib                           x86_64                     1.2.7-18.el7                      base                      90 k

事務概要
============================================================================================================================
安裝  1 軟件包
升級           ( 1 依賴軟件包)

總下載量:140 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
zlib-1.2.7-18.el7.x86_64.rpm   FAILED                                          
http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/zlib-1.2.7-18.el7.x86_64.rpm: [Errno 12] Timeout on http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/zlib-1.2.7-18.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
zlib-devel-1.2.7-18.el7.x86_64 FAILED                                          
http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.x86_64.rpm: [Errno 12] Timeout on http://centos.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
(1/2): zlib-devel-1.2.7-18.el7.x86_64.rpm                                                            |  50 kB  00:00:00     
(2/2): zlib-1.2.7-18.el7.x86_64.rpm                                                                  |  90 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------
總計                                                                                        3.9 kB/s | 140 kB  00:00:36     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : zlib-1.2.7-18.el7.x86_64                                                                                1/3 
  正在安裝    : zlib-devel-1.2.7-18.el7.x86_64                                                                          2/3 
  清理        : zlib-1.2.7-17.el7.x86_64                                                                                3/3 
  驗證中      : zlib-devel-1.2.7-18.el7.x86_64                                                                          1/3 
  驗證中      : zlib-1.2.7-18.el7.x86_64                                                                                2/3 
  驗證中      : zlib-1.2.7-17.el7.x86_64                                                                                3/3 

已安裝:
  zlib-devel.x86_64 0:1.2.7-18.el7                                                                                          

作爲依賴被升級:
  zlib.x86_64 0:1.2.7-18.el7                                                                                                

完畢!

 依賴庫zlib安裝完成,再次進行預編譯

[root@localhost nginx-1.16.1]# ./configure
checking for OS
 + Linux 3.10.0-693.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-36) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... found
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"

 預編譯完成後,ls查看目錄文件,會多出“Makefile”目錄

[root@localhost nginx-1.16.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

使用make命令編譯,編譯過程內容過多,中間內容不在貼出 

[root@localhost nginx-1.16.1]# make
.......
.........
.......
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: 離開目錄“/root/nginx-1.16.1”

 編譯完成後,安裝nginx

[root@localhost nginx-1.16.1]# make install
make -f objs/Makefile install
make[1]: 進入目錄“/root/nginx-1.16.1”
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
	'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
	'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
	'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
	|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
make[1]: 離開目錄“/root/nginx-1.16.1”

 至此nginx安裝完成,啓動nginx查看進程(注意nginx使用80端口,如有其它應用佔用,啓動會失敗,可停止佔用端口的應用或修改nginx端口)

[root@localhost nginx-1.16.1]# cd objs
[root@localhost objs]# ./nginx
[root@localhost objs]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13233/nginx: master 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      909/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1156/master         
tcp6       0      0 :::22                   :::*                    LISTEN      909/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1156/master   

3、使用網頁訪問nginx(先臨時關閉防火牆,查看防火牆已關閉)

[root@localhost objs]# systemctl stop firewalld.service
[root@localhost objs]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 一 2019-08-26 10:54:14 CST; 12s ago
     Docs: man:firewalld(1)
  Process: 599 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 599 (code=exited, status=0/SUCCESS)

8月 26 09:59:16 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 26 09:59:17 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: ICMP type 'beyond-scope' is not supported by the kern...pv6.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP typ...ime.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: ICMP type 'failed-policy' is not supported by the ker...pv6.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP ty...ime.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: ICMP type 'reject-route' is not supported by the kern...pv6.
8月 26 09:59:18 localhost.localdomain firewalld[599]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP typ...ime.
8月 26 10:54:13 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
8月 26 10:54:14 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.

使用瀏覽器訪問192.168.9.101(當前安裝Nginx服務器對應的IP地址),出現以下畫面,說明安裝成功(訪問nginx的主機需與centos同一網段或做net映射)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章