CentOS 7 离线安装nginx1.18


前言

由于每次安装nginx的环境都不同,有时有外网,有时没有。现就无外网环境的CentOS7上安装nginx1.18,为以后用到时提供参考。


一、环境准备

名称 版本 下载源
CentOS 7.5 CentOS官网下载地址
nginx 1.18 nginx官网下载地址

1.1 CentOS的安装

以前记录过在线安装Linux相关软件的文章,版本是CentOS7.2,可以参考。

1.2 下载相应的nginx包

在这里插入图片描述

二 安装nginx

2.1 上传到服务器

# 创建文件夹并上传
mkdir /usr/local/software/nginx

2.2 安装

# 安装
sudo yum install -y nginx-1.18.0-2.el7.ngx.x86_64.rpm
# 设置开机自启
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

2.3 查看nginx版本及状态

# 查看版本
nginx -v
# 查看状态
service nginx status 或 
systemctl status nginx.service
# 启动、停止
service nginx start/stop 或
systemctl start/stop nginx.service

2.4 开放防火墙8080端口(执行最后两步即可)

# 关闭防火请
sudo systemctl stop firewalld.service
# 禁用防火墙
sudo systemctl disable firewalld.service
# 重启防火墙
sudo systemctl restart firewalld.service
# 查看防火墙状态
firewall-cmd --state
# 开启防火墙
sudo systemctl start firewalld.service
# 开启防火墙8080端口
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
# 重新载入配置
sudo firewall-cmd --reload

2.5 nginx配置文件

# 配置文件位置
/etc/nginx/conf.d/default.conf

猜你喜欢

转载自blog.csdn.net/qq_43430759/article/details/126099188