# LLM 论文图书馆 — Nginx 反向代理配置
# 部署路径: /etc/nginx/sites-available/llm-library

server {
    listen 80;
    server_name your-domain.com;

    # 安全头
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "no-referrer" always;

    # 限制请求速率 (防止滥用)
    limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

    # API 代理
    location /api/ {
        proxy_pass http://127.0.0.1:8000;
        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;
        limit_req zone=api burst=20 nodelay;
    }

    # PDF 代理 — 强制 inline 阻止 IDM 弹下载
    location /papers/ {
        proxy_pass http://127.0.0.1:8741;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_read_timeout 60s;
        # 追加 inline header 防止 IDM 拦截
        add_header Content-Disposition "inline" always;
        add_header X-Content-Type-Options "nosniff" always;
    }

    # 静态文件直接由 Nginx 服务 (性能更好)
    location /style.css { 
        alias /opt/llm-library/static/style.css; 
        expires 1d;
    }
    location /app.js { 
        alias /opt/llm-library/static/app.js; 
        expires 1d;
    }
    location /favicon.ico {
        return 204;
    }

    # 首页
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
    }
}
