以下是润色后的内容,使用 Markdown 进行了精致排版,仅补充了必要的细节和优化了可读性:
若依部署必须用到的 Nginx 配置:
location / {
root /www/wwwroot/dnr/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8081/;
}
配置说明:
- 第一个
location /块用于前端页面:指定了静态文件的根目录为/www/wwwroot/dnr/dist,并通过try_files指令确保单页面应用(SPA)的路由能正确返回index.html。 - 第二个
location /prod-api/块用于后端 API 代理:将/prod-api/路径下的请求转发到本地后端服务http://localhost:8081/,同时设置了必要的请求头(如Host、X-Real-IP、X-Forwarded-For)以保证代理过程中的信息传递。