惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
O
OpenAI News
Cloudbric
Cloudbric
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
J
Java Code Geeks
Help Net Security
Help Net Security
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
H
Help Net Security
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
Jina AI
Jina AI
S
Security @ Cisco Blogs
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
P
Proofpoint News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
F
Fortinet All Blogs
S
Securelist
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
小众软件
小众软件
T
Tenable Blog
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
博客园 - 叶小钗
N
News | PayPal Newsroom
A
About on SuperTechFans
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity

博客园 - lizhigang

DBeaver 打开 utf8的sql文件 SMT 贴片机与 MES 系统集成指南 容器访问外部服务(10.100.1.90:9090)防火墙规则配置总结 Docker 容器间通信故障排查与修复操作总结 Docker 容器部署与运维总结报告 Nginx Docker 容器白名单配置操作总结 使用 pnpm 构建 Vue2 项目操作总结(Node 16 → Node 22) 前端项目 Docker 镜像构建完整操作总结 Windows 11 下使用 MySQL Workbench 还原多数据库备份文件操作指南 在 WSL2 + Docker Desktop 环境下构建前后端 Docker 镜像 从内网私有仓库迁移镜像到阿里云 ACR 完整指南 wsl网络设置允许访问ssh(端口22) 在 Windows 11 上安装 Docker 访问数据库报错 Windows系统运行RuoYi-Vue完整指南 RuoYi-Vue 项目结构分析 win11 报错 windows 11 如何使用 Microsoft Hyper-V VMware 替代产品 IntelliJ IDEA 社区版支持 Spring Boot 开发说明文档 imes开发部署(IDEA社区版 差异) IntelliJ IDEA 社区版默认支持 Spring Boot 吗? imes开发部署 IDEA 端口被占用 解决办法 使用MySQL Workbench进行数据库备份 ruoyi-nbcio ktg-mes、ktm-mes-ui部署 Widows下安装和配置Redis Windows下Redis安装与配置全攻略 mes开源 imes:注意 若依框架:开源
Nginx配置
lizhigang · 2026-03-25 · via 博客园 - lizhigang

若依(前后端分离版)的标准架构是:
静态资源(html, css, js):由 Nginx 直接从 /var/www/ruoyi 读取并返回给浏览器。
接口请求(/prod-api/...):由 Nginx 反向代理转发给后端的 8080 端口。

请使用以下配置替换你现有的配置:

server {
listen 80;
server_name _;

1. 设置前端静态文件根目录

root /var/www/ruoyi;
index index.html;

2. 处理前端页面请求 (核心修改)

location / {
# 尝试查找真实文件,找不到则返回 index.html (支持 Vue 刷新不404)
try_files uri uri/ /index.html;

【注意】这里不要写 proxy_pass!否则又变回直接访问后端了

}

3. 处理后端接口请求 (反向代理)

若依默认的前端请求前缀是 /prod-api,请根据你的前端配置文件(.env.production)确认

location /prod-api/ {
proxy_set_header Host http_host;
proxy_set_header X-Real-IP remote_addr;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto scheme;

转发到后端 8080 端口

注意:末尾的 / 很重要,它会去掉 /prod-api/ 前缀再传给后端

proxy_pass http://127.0.0.1:8080/;
}

可选:禁止访问隐藏文件

location ~ /. {
deny all;
}
}

🚀 操作步骤

编辑配置文件:
sudo nano /etc/nginx/sites-available/ruoyi
# 或者你的配置文件路径,例如 /etc/nginx/conf.d/ruoyi.conf

将内容替换为上面的代码。

检查配置语法:
sudo nginx -t

必须显示 syntax is ok 和 test is successful。

重载 Nginx:
sudo systemctl reload nginx

再次访问:
在浏览器访问 http://你的服务器IP
现在应该能看到若依的登录界面(因为 Nginx 直接提供了 index.html)。
尝试输入账号密码登录。如果配置正确,登录请求(/prod-api/login)会被 Nginx 转发给后端,从而成功登录。

💡 关键点解释
root /var/www/ruoyi;: 告诉 Nginx 去这个文件夹找 index.html。
try_files ...: 这是 Vue/React 单页应用必须的,防止刷新页面变白。
location /prod-api/: 只有以 /prod-api/ 开头的请求(即登录、获取数据等接口)才会被转发给 8080 端口。其他请求(如加载 .js, .css, 图片)都由 Nginx 自己处理。
proxy_pass ... /;: 注意末尾的斜杠。它会将 http://你的IP/prod-api/system/login 转换为 http://127.0.0.1:8080/system/login 传给后端,符合若依后端的接口路径要求。