nginx(一):CentOS7离线安装nginx

大家好,我是欧阳方超,可以扫描下方二维码关注我的公众号“欧阳方超”,后续内容将在公众号首发。在这里插入图片描述
在这里插入图片描述

1、概述

在CentOS 7系统中,离线安装Nginx是一个常见的需求,特别是在没有互联网连接的环境中。本文将详细介绍离线安装Nginx的步骤,包括所需的依赖包和安装过程。

2、nginx安装

2.1、下载安装包

下载安装包并将其上传到服务器后解压:

[root@bogon software]# tar -zxvf nginx-1.24.0.tar.gz

解压后的内容如下:

drwxr-xr-x 6 mongod mongod    326 Sep 10 02:11 auto
-rw-r--r-- 1 mongod mongod 323312 Apr 10  2023 CHANGES
-rw-r--r-- 1 mongod mongod 494234 Apr 10  2023 CHANGES.ru
drwxr-xr-x 2 mongod mongod    168 Sep 10 02:11 conf
-rwxr-xr-x 1 mongod mongod   2611 Apr 10  2023 configure
drwxr-xr-x 4 mongod mongod     72 Sep 10 02:11 contrib
drwxr-xr-x 2 mongod mongod     40 Sep 10 02:11 html
-rw-r--r-- 1 mongod mongod   1397 Apr 10  2023 LICENSE
drwxr-xr-x 2 mongod mongod     21 Sep 10 02:11 man
-rw-r--r-- 1 mongod mongod     49 Apr 10  2023 README
drwxr-xr-x 9 mongod mongod     91 Sep 10 02:11 src

2.2、安装nginx

执行./configure

[root@bogon nginx-1.24.0]# ./configure
checking for OS
 + Linux 3.10.0-862.el7.x86_64 x86_64
checking for C compiler ... not found

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

从https://vault.centos.org/7.3.1611/os/x86_64/Packages/下载相关rpm包,并上传到服务器(目录自行指定):

-rw-r--r-- 1 root root  6225248 Sep 10 02:25 cpp-4.8.5-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 16957504 Sep 10 02:25 gcc-4.8.5-11.el7.x86_64.rpm
-rw-r--r-- 1 root root  3767280 Sep 10 02:25 glibc-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root 12038164 Sep 10 02:25 glibc-common-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root  1106292 Sep 10 02:25 glibc-devel-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root   684244 Sep 10 02:25 glibc-headers-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root  1599280 Sep 10 02:25 glibc-static-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root   213324 Sep 10 02:25 glibc-utils-2.17-157.el7.x86_64.rpm
-rw-r--r-- 1 root root    51732 Sep 10 02:25 libmpc-1.0.1-3.el7.x86_64.rpm
-rw-r--r-- 1 root root    32904 Sep 10 02:25 libmpc-devel-1.0.1-3.el7.x86_64.rpm
-rw-r--r-- 1 root root   208316 Sep 10 02:25 mpfr-3.1.1-4.el7.x86_64.rpm
-rw-r--r-- 1 root root    69904 Sep 10 02:25 mpfr-devel-3.1.1-4.el7.x86_64.rpm

执行安装命令

[root@bogon gccrpm]# rpm -ivh *.rpm --nodeps --force
Preparing...                          ################################# [100%]
Updating / installing...
   1:glibc-common-2.17-157.el7        ################################# [  6%]
   2:glibc-2.17-157.el7               ################################# [ 13%]
   3:mpfr-3.1.1-4.el7                 ################################# [ 19%]
   4:libmpc-1.0.1-3.el7               ################################# [ 25%]
   5:libstdc++-4.8.5-11.el7           ################################# [ 31%]
   6:libstdc++-devel-4.8.5-11.el7     ################################# [ 38%]
   7:cpp-4.8.5-11.el7                 ################################# [ 44%]
   8:mpfr-devel-3.1.1-4.el7           ################################# [ 50%]
   9:glibc-headers-2.17-157.el7       ################################# [ 56%]
  10:glibc-devel-2.17-157.el7         ################################# [ 63%]
  11:gcc-4.8.5-11.el7                 ################################# [ 69%]
  12:gcc-c++-4.8.5-11.el7             ################################# [ 75%]
  13:glibc-static-2.17-157.el7        ################################# [ 81%]
  14:libmpc-devel-1.0.1-3.el7         ################################# [ 88%]
  15:libstdc++-static-4.8.5-11.el7    ################################# [ 94%]
  16:glibc-utils-2.17-157.el7         ################################# [100%]

在这里插入图片描述
验证gcc是否安装成功

[root@bogon gccrpm]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

验证g++是否安装成功

[root@bogon gccrpm]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure执行完之后:

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"

执行

make
make install

2.3、启动nginx

这种方式安装的nginx目录在/usr/local/nginx。
启动nginx

[root@bogon nginx]# ./sbin/nginx
[root@bogon nginx]#
[root@bogon nginx]#
[root@bogon nginx]# netstat -tunlp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7452/nginx: master

2.4、验证

见到熟悉的页面(curl方式访问的):

[root@bogon nginx]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

3、总结

通过上述介绍,可以在CentOS 7系统中成功进行Nginx的离线安装。确保在安装前准备好所有必需的依赖包,如gcc、pcre、pcre-devel、zlib-devel,以避免出现依赖问题。
我是欧阳方超,把事情做好了自然就有兴趣了,如果你喜欢我的文章,欢迎点赞、转发、评论加关注。我们下次见。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值