server {
    listen 8989;
    server_name mengyalinkfly-frontend;  # 前端服务器IP
    
    root /shumengya/www/mengyalinkfly-frontend;
    index index.html index.htm;
    
    # 短链跳转：4位字符的路径直接转发到后端服务器（支持wget等命令行工具）
    location ~ "^/[a-zA-Z0-9]{4}$" {
        proxy_pass http://192.168.1.233:7878;
        proxy_set_header Host short.api.shumengya.top;
        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;
    }
    
    # 后端 API 代理到后端服务器
    location /api {
        proxy_pass http://192.168.1.233:7878;
        proxy_set_header Host short.api.shumengya.top;
        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;
    }
    
    # 前端路由
    location / {
        try_files $uri $uri/ /index.html;
    }
    
    # 禁止访问隐藏文件
    location ~ /\. {
        deny all;
    }
    
    # 设置静态文件缓存
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }
}