Linux 离线安装Nginx

Linux 离线安装Nginx

在Linux系统下离线安装nginx ,如果没有安装gcc等c编译器的依赖,一个一个rpm下载,下载完安装,一个依赖三个,特别麻烦,安装gcc per 完全可以从本地镜像中安装,修改yum源为本地镜像,然后使用yum进行安装编译器,会方便很多。

一、yum源镜像挂载到本地镜像

  • 1. 挂载镜像到 /mnt/cdrom
mkdir /mnt/cdrom
mount -t iso9660 /dev/cdrom /mnt/cdrom
  • 2. 切换目录到 /etc/yum.repos.d/
cd /etc/yum.repos.d/
  • 3. 将除了 CentOS-Media.repo 之外的文件修改其文件名
mv CentOS-Base.repo CentOS-Base.repo.bak
mv CentOS-CR.repo CentOS-CR.repo.bak
mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
mv CentOS-fasttrack.repo CentOS-fasttrack.repo.bak
mv CentOS-Sources.repo CentOS-Sources.repo.bak
mv CentOS-Vault.repo CentOS-Vault.repo.bak
  • 4. 修改 CentOS-Media.repo 文件
将其中的baseurl修改为
baseurl=file:///mnt/cdrom/
启用本地仓库
enabled=1

二、 安装Nginx相关依赖

  • 1.依赖和编译器安装
yum -y install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
  • 2.解压Nginx并安装
tar -zxvf nginx-1.18.0.tar.gz 
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx/
make && make install

三、启动Nginx

cd /usr/local/nginx/sbin/
./nginx

附一:

[root@localhost sbin]# ./nginx 
nginx: [alert] could not open error log file: open() "/usr/local/nginx//logs/error.log" failed (2: No such file or directory)
2020/11/09 17:19:21 [emerg] 9791#0: open() "/usr/local/nginx//logs/access.log" failed (2: No such file or directory)

解决:

[root@localhost nginx]# mkdir logs
[root@localhost nginx]# touch logs/error.log
[root@localhost nginx]# touch logs/access.log
[root@localhost nginx]# ./sbin/nginx

你可能感兴趣的:(Linux)