用途:voip 项目前端服务 / 反向代理 安装包位置:../resource/ 统一静态资源目录(点击下方各平台链接直接下载)

一、版本说明

每个平台对应的安装包,点击文件名即可下载(安装包统一存放在 ../resource/ 目录):

Redhat 7 / CentOS 7 —— nginx-1.22.0-2.el7.ngx.x86_64.rpm

Redhat 8 / CentOS 8 —— nginx-1.22.1-2.el8.ngx.x86_64.rpm

麒麟 V10 —— nginx-1.22.1-2.el8.ngx.x86_64.rpm

监控组件说明

本 Nginx 版本已集成状态监控能力,可对接平台监控体系(Prometheus / Zabbix 等):

  • stub_status 模块:Nginx 自带,用于暴露活跃连接数、请求数、读写等待数等基础指标
  • 监控端点:在配置中开启 stub_status 后,通过 http://<服务器IP>/nginx_status 即可采集指标

注意:安装前请根据服务器操作系统选择对应平台的 RPM 包,切勿跨平台安装(el7 与 el8 包不通用)。

二、安装说明

1. 上传安装包

将对应平台的 RPM 包上传至目标服务器:

1
2
3
4
5
# 在服务器上创建存放目录
mkdir -p /usr/local/src/

# 通过 scp 从本地上传(在本地机器执行,按目标平台替换包名)
scp "/Users/zhoumeng62/Documents/Obsidian Vault/voip/resource/nginx-1.22.0-2.el7.ngx.x86_64.rpm" root@<服务器IP>:/usr/local/src/

2. 执行安装

进入安装包所在目录,使用 yum 进行本地安装:

1
2
3
4
5
6
7
cd /usr/local/src/

# Redhat 7 / CentOS 7
yum install ./nginx-1.22.0-2.el7.ngx.x86_64.rpm

# Redhat 8 / CentOS 8 / 麒麟 V10
yum install ./nginx-1.22.1-2.el8.ngx.x86_64.rpm

说明:使用 yum install ./包名 而非 rpm -ivh,是因为 yum 会自动解决依赖关系。命令中的 ./ 表示安装当前目录下的本地包,必须先 cd 到包所在目录。

三、配置修改

Nginx 配置文件目录:/etc/nginx/

主要文件说明:

文件 / 目录 用途
/etc/nginx/nginx.conf 主配置文件(全局、http 块)
/etc/nginx/conf.d/ 站点配置目录(业务自定义 server 配置放这里)

编辑主配置文件:

1
vim /etc/nginx/nginx.conf

按业务需求修改 server 块中的 listen 端口、server_name、location 反向代理目标等参数。

开启监控端点(可选)

需要采集 Nginx 指标的场景,添加 stub_status 配置:

1
2
3
4
5
6
7
8
9
10
11
server {
listen 80;
server_name localhost;

location /nginx_status {
stub_status;
access_log off;
# allow 192.168.0.0/16; # 按需放开允许访问的监控服务器 IP 段
# deny all;
}
}

四、启动服务

设置 Nginx 开机自启并立即启动:

1
systemctl enable nginx.service && systemctl start nginx.service

五、验证

1
2
3
4
5
6
7
8
# 查看服务状态
systemctl status nginx.service

# 查看监听端口
netstat -tlnp | grep nginx

# 测试访问
curl -I http://127.0.0.1

六、常用运维命令

操作 命令
启动 systemctl start nginx.service
停止 systemctl stop nginx.service
重启 systemctl restart nginx.service
重新加载配置(不停机) nginx -s reload
检查配置语法 nginx -t
查看版本 nginx -v

© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!