# docker/frontend/nginx.conf server { listen 80; server_name localhost; # 或者你的域名 #charset koi8-r; #access_log /var/log/nginx/host.access.log main; error_log /var/log/nginx/error.log warn; location / { root /usr/share/nginx/html; index index.html index.htm; # 解决 Vue Router History 模式下刷新 404 的问题 try_files $uri $uri/ /index.html; } # 配置 API 代理,将前端的 /prod-api 请求转发给后端服务 # /prod-api 这个前缀需要与 ruoyi-ui/.env.production 中的 VUE_APP_BASE_API 一致 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; # 转发到后端服务的地址和端口 (ruoyi-backend 是 docker-compose 中的服务名) proxy_pass http://ruoyi-backend:8080/; # 可选: 移除 /prod-api 前缀转发给后端 # rewrite ^/prod-api/(.*)$ /$1 break; # RuoYi 后端通常不需要移除前缀,可以直接接收 /prod-api/ 开头的请求 } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }