# ============================================
# LiteMall 轻商城 - Nginx 反向代理配置
# ============================================
# 使用说明：
#   1. 将 server_name 替换为你的实际域名
#   2. 上传到服务器 /etc/nginx/sites-available/litemall.conf
#   3. ln -sf /etc/nginx/sites-available/litemall.conf /etc/nginx/sites-enabled/
#   4. nginx -t && systemctl reload nginx

server {
    listen 80;
    server_name litemall.你的域名.com;  # ← 修改为实际域名

    # 字符集
    charset utf-8;

    # 静态资源缓存（图片、CSS、JS）
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
        proxy_pass http://127.0.0.1:3001;
        expires 7d;
        add_header Cache-Control "public, immutable";
        access_log off;
    }

    # 上传文件目录
    location /uploads/ {
        proxy_pass http://127.0.0.1:3001;
        expires 1d;
        add_header Cache-Control "public";
    }

    # API请求（反向代理到Node.js）
    location /api/ {
        proxy_pass http://127.0.0.1:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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_read_timeout 60s;
        proxy_send_timeout 60s;
        proxy_buffering off;
    }

    # 前台页面（PC端 / H5 / 管理后台 / MiniProgram）
    location / {
        proxy_pass http://127.0.0.1:3001;
        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;
    }

    # 安全头
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

    # 限制请求大小
    client_max_body_size 20m;

    # 日志
    access_log /var/log/nginx/litemall-access.log;
    error_log /var/log/nginx/litemall-error.log;
}
