RockyLinux 9快速部署Nginx+HTTPS(基于DNF安装)

B站影视 电影资讯 2025-03-26 00:25 1

摘要:针对RockyLinux 9用户,通过DNF包管理器快速搭建Nginx服务并配置HTTPS加密,以下是优化后的实战流程,兼顾效率与安全性。

针对RockyLinux 9用户,通过DNF包管理器快速搭建Nginx服务并配置HTTPS加密,以下是优化后的实战流程,兼顾效率与安全性。

1. 一键安装Nginx及依赖


RockyLinux 9官方仓库已集成稳定版Nginx,无需编译直接安装:

sudo dnf update -y # 更新系统sudo dnf install -y nginx # 安装Nginx

2. 启动服务并设置开机自启

sudo systemctl start nginxsudo systemctl enable nginx

3. 验证安装状态

sudo systemctl status nginx # 查看运行状态curl -I http://localhost # 测试默认页面(应返回200 OK)

1. 安装Certbot工具


通过EPEL仓库获取证书管理工具:

sudo dnf install -y epel-releasesudo dnf install -y certbot python3-certbot-nginx

2. 申请免费SSL证书
替换域名your_domain.com后执行:

sudo certbot --nginx -d your_domain.com # 按提示完成域名验证

证书将自动部署到/etc/letsencrypt/live/your_domain.com/目录。

1. 配置AI模型服务代理
编辑站点配置文件/etc/nginx/conf.d/ai_service.conf:

server {listen 443 ssl;server_name your_domain.com;ssl_certificate /etc/letsencrypt/live/your_domain.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/your_domain.com/privkey.pem;ssl_protocols TLSv1.2 TLSv1.3; # 启用TLS 1.3提升性能# 反向代理到AI模型服务(假设本地端口8000)location / {proxy_pass http://127.0.0.1:8000;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}# HTTP强制跳转HTTPSserver {listen 80;server_name your_domain.com;return 301 https://$host$request_uri;}

2. 重载配置生效

sudo nginx -t # 语法检查sudo systemctl reload nginx

1. 开放必要端口

sudo firewall-cmd --permanent --add-service={http,https} # 开放80/443 TCPsudo firewall-cmd --permanent --add-port=443/udp # 若需HTTP/3需开放UDP 443sudo firewall-cmd --reload

2. 禁用默认测试页面

sudo rm -rf /usr/share/nginx/html/* # 删除默认静态文件五、性能调优建议

1. 进程与连接数优化
修改/etc/nginx/nginx.conf主配置:

worker_processes auto; # 自动匹配CPU核心数events {worker_connections 4096; # 单进程连接数上限use epoll; # 高性能事件模型}

2. 启用Gzip压缩
在http{}块内添加:

gzip on;gzip_types text/plain application/json;gzip_min_length 1024; # 超过1KB才压缩六、关于HTTP/3的说明

当前通过DNF安装的Nginx暂不支持HTTP/3协议。如需启用:

方案一:从Nginx官方仓库安装包含QUIC模块的版本(需手动配置)方案二:参考Nginx官方文档编译集成Cloudflare Quiche库# HTTPS服务验证curl -I https://your_domain.com # 检查SSL协议版本journalctl -u nginx -f # 实时查看日志# 性能监控sudo dnf install -y htophtop # 查看CPU/内存占用

通过以上步骤,30分钟内即可在RockyLinux 9上完成Nginx+HTTPS的高效部署,为AI模型服务提供安全可靠的前端入口。

来源:linux运维菜

相关推荐