Centos7离线安装Nginx亲测版

2022年6月9日13:06:24

Centos7 Nginx编译包制作

找一台可连接互联网的虚拟机来制作编译好的Nginx包,具体操作如下

1、准备一台虚拟机(可访问互联网)

2、安装所需插件

$ yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc-c++ libtool

3、准备nginx包

3.1、下载

通过网页下载,然后上传到Centos7系统的/opt目录下

或者,直接在Centos7系统下接命令下载到/opt目录下

$ cd /opt
$ wget http://nginx.org/download/nginx-1.14.0.tar.gz

3.2 解压

解压 nginx-1.14.0.tar.gz,并重命名为 nginx

$ cd /opt
$ tar zxf nginx-1.14.0.tar.gz

3.3 重命名

$ cd /opt
$ mv nginx-1.14.0 nginx

4、配置nginx

$ cd /opt/nginx
$ ./configure --prefix=/usr/local/nginx  --conf-path=/usr/local/nginx/conf/nginx.conf  --error-log-path=/usr/local/nginx/log/error.log --http-log-path=/usr/local/nginx/log/access.log

注:此处配置Nginx安装目录为 /usr/local/nginx,将来安装时,会在/usr/local/下生成nginx目录。

5、编译Nginx

$ cd /opt/nginx
$ make

6、打包Nginx

$ cd /opt
$ tar cvzf nginx.hasmake.1.14.0.tar.gz nginx

打包后,会在/opt 目录下生成一个 nginx.hasmake.1.14.0.tar.gz 包

Centos7 Nginx离线安装

  • 上传包

应用 nginx.hasmake.1.14.0.tar.gz 已编译好的包,上传到对应的Centos7系统上,比如此处放到 /opt 目录下,则安装很简单

$ cd /opt
$ tar zxf nginx.hasmake.1.14.0.tar.gz	#解压后得到 nginx 目录
$ cd nginx								#进入 nginx 目录
$ make install							#安装
  • 解压

安装完成后,将会在 /usr/local 目录下,生成一个 nginx 目录。如下

$ ll /usr/local/nginx
drwxr-xr-x. 2 root root 4096 11月 10 14:22 conf
drwxr-xr-x. 2 root root   38 11月 10 14:22 html
drwxr-xr-x. 2 root root    6 11月 10 14:22 log
drwxr-xr-x. 2 root root    6 11月 10 14:22 logs
drwxr-xr-x. 2 root root   18 11月 10 14:22 sbin
  • nginx 配置文件测试
$ /usr/local/nginx/sbin/nginx -t
  • nginx 启动
$ /usr/local/nginx/sbin/nginx
  • 作者:eijiyey
  • 原文链接:https://blog.csdn.net/eijiyey/article/details/123183948
    更新时间:2022年6月9日13:06:24 ,共 1267 字。