以下操作因为系统是最小安装,所以会需要安装的依赖和命令较多,实验环境,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) <security@centos.org>"指纹       : 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 Mgcc                             x86_64                 4.8.5-36.el7_6.2                      updates                  16 Mglibc-devel                     x86_64                 2.17-260.el7_6.6                      updates                 1.1 Mglibc-headers                   x86_64                 2.17-260.el7_6.6                      updates                 684 kkernel-headers                  x86_64                 3.10.0-957.27.2.el7                   updates                 8.0 Mlibmpc                          x86_64                 1.0.1-3.el7                           base                     51 klibstdc++-devel                 x86_64                 4.8.5-36.el7_6.2                      updates                 1.5 Mmpfr                            x86_64                 3.1.1-4.el7                           base                    203 k
为依赖而更新:glibc                           x86_64                 2.17-260.el7_6.6                      updates                 3.7 Mglibc-common                    x86_64                 2.17-260.el7_6.6                      updates                  12 Mlibgcc                          x86_64                 4.8.5-36.el7_6.2                      updates                 102 klibgomp                         x86_64                 4.8.5-36.el7_6.2                      updates                 158 klibstdc++                       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/MakefileConfiguration summary+ using system PCRE library+ OpenSSL library is not used+ using system zlib librarynginx 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 daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: inactive (dead) since 一 2019-08-26 10:54:14 CST; 12s agoDocs: 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. Centos7 下源码安装nginx

    一.安装必要的库: (nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库) 选定/usr/local/nginx 为安装目录 ,文中版 ...

  2. centos7 mysql 源码安装_CentOS7.4 源码安装MySQL8.0的教程详解

    MySQL 8 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 以下为本人2018.4.23日安装过程的记录.整个过程大 ...

  3. 阿里云服务器——centos7下源码安装tomcat9

    阿里云服务器--centos7下源码安装tomcat9 (第一次写文章,俺会努力的) 首先进入src文件夹: cd /usr/local/src 使用wget命令下载tomcat : wget htt ...

  4. CentOS7 下源码安装MPlayer播放器

    最近学习了build源码安装软件,老师布置的习题,用所学过的知识安装mplayer播放器.通过上网我了解到在linux系统下,mplayer播放器十分强大好用.但是,在安装的过程中遇到了很多问题,比如 ...

  5. linux下源码安装nginx

    LNMP模式 后续继续更新,先搭建nginx 安装环境gcc gcc-c++ 2 下载源码包解压 配置第一个报错 安装openssl openssl-devel yum -y install open ...

  6. 在Centos7下源码安装配置Redis

    1.安装前准备开发环境 安装pcre开发包: yum install -y pcre-devel  安装编译源码所需的工具和库:yum install gcc gcc-c++ ncurses-deve ...

  7. centos7下源码安装mysql5.6_Centos7 源码安装mysql5.6

    mysql下载 谷歌 mysql->community->mysql community server->mysql community server 5.6->Select ...

  8. centos7源码安装mysql报错_CentOS7 下源码安装MySQL数据库 8.0.11

    本文主要向大家介绍了CentOS7 下源码安装MySQL数据库 8.0.11,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. CentOS7 下源码安装MySQL 8.0.11 系 ...

  9. CentOS7下源码编译安装MySQL5.6.4

    CentOS7下源码编译安装MySQL5.6.4 写这篇博客的主要原因是:请看上一篇博客:CentOS7下更改MySQL5.6.4默认的数据存储位置.对,当初通过rpm安装的mysql5.6.4,一切 ...

最新文章

  1. 激发企业大“智慧” | 深度赋能AI全场景 揭秘你不知道的移动云
  2. Storm和MR及Spark Streaming的区别
  3. .NET 开源软件开发BIM工具包xBIM
  4. oracle之基本的过滤和排序数据
  5. 【HDU - 5475】An easy problem(线段树,思维)
  6. SharePoint 2013 Workflow - Advanced Workflow Debugging with Fiddler
  7. 【★】路由环路大总结!
  8. 对linux下loop设备的理解。
  9. 用虚拟串口进行串口调试
  10. 使用百度云OCR识别文字
  11. arduino智能浇花系统_基于Arduino单片机的智能浇花器
  12. 深度学习图像算法在内容安全领域的应用
  13. Android视频编辑器(二)预览、录制视频加上水印和美白磨皮效果
  14. 阿里性能专家全方位对比Jmeter和Locust,到底谁更香?
  15. 计算机专业英语四个部分思维导图,一张思维导图,彻底分清英语五大基本句型...
  16. 机器学习深度学习中反向传播之偏导数链式法则
  17. 核电站问题 动态规划
  18. 利用github和godaddy搭建使用二级域名的个人主页
  19. (转)活出生命的成就
  20. Web后端servlet—使用servlet的Part接口实现单文件多文件上传、以及日期格式转换为sql日期格式的实现

热门文章

  1. tp3调用微信jsjdk扫一扫接口,并实现微信扫一扫签到
  2. Nginx推流负载均衡配置
  3. ios极光推送 App收到推送消息时,修改BadgeNumber,同时点击状态栏消息以后跳到指定的页面和静默推送
  4. 基于注解的Excel导出万能模板
  5. jdk1.8 stream() 把List <String>变成String
  6. 程序员进阶攻略-笔记-051~061(完)
  7. ftp下载工具绿色版,ftp下载工具有绿色版的吗?教程详解
  8. java红牛农场,在新加坡的,完一朋友一个夜班喝5瓶红牛。 下班坐地
  9. 量子计算之量子压缩编码(dense coding)
  10. Linux目录文件操作命令篇--(工作常用命令的深度使用,小白必收藏)