# Nginx 静态页面配置模板
# 使用时替换以下变量：
#   {PORT} - 端口号
#   {DEPLOY_DIR} - 部署目录路径
#   {IP} - 服务器 IP

server {
    listen {PORT};
    server_name {IP};
    
    # 部署目录
    root {DEPLOY_DIR};
    index index.html index.htm;
    
    # 日志配置
    access_log /var/log/nginx/deploy_{PORT}_access.log;
    error_log /var/log/nginx/deploy_{PORT}_error.log warn;
    
    # 静态文件缓存优化
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot|otf|woff)$ {
        expires 30d;
        add_header Cache-Control "public";
        add_header X-Static-File "true";
    }
    
    # HTML 文件不缓存
    location ~* \.html$ {
        expires -1;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
    }
    
    # SPA 路由支持（单页应用）
    # 如果不需要可删除此配置
    location / {
        try_files $uri $uri/ /index.html;
    }
    
    # Gzip 压缩
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
    gzip_disable "MSIE [1-6]\.";
    
    # 安全头
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    
    # 禁止访问隐藏文件
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    
    # 禁止访问备份文件
    location ~* \.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)$ {
        deny all;
        access_log off;
        log_not_found off;
    }
    
    # 限制请求大小
    client_max_body_size 10M;
    
    # 连接优化
    keepalive_timeout 65;
    keepalive_requests 100;
}
