linux7/centos7下源码安装nginx-1.16.1详解

以下操作因为系统是最小安装,所以会需要安装的依赖和命令较多,实验环境,centos7ip:192.168.11.123

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) "
 指纹       : 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= 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= 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.11.123,出现以下画面,说明安装成功(访问nginx的主机需与centos同一网段或做net映射)
linux7/centos7下源码安装nginx-1.16.1详解_第1张图片

你可能感兴趣的:(nginx配置)