upstream easycard_backend { server 127.0.0.1:8112; keepalive 32; } server { listen 80; server_name _; client_max_body_size 20m; location = /card { return 301 /card/; } # 按服务器实际路径替换为前端 dist 目录。 root /root/easycard/dist; index index.html; # 仅将 /card/api 前缀映射到后端 8112 服务。 # 例如:/card/api/v1/system/ping -> /api/v1/system/ping location ^~ /card/api/ { rewrite ^/card(/.*)$ $1 break; proxy_pass http://easycard_backend; proxy_http_version 1.1; proxy_set_header Host $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; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Prefix /card; proxy_redirect off; } # 托管前端静态资源与 history 路由。 location ^~ /card/ { rewrite ^/card/(.*)$ /$1 break; try_files $uri $uri/ /index.html; } }