server {
    listen 80;
    server_name localhost;
    root /usr/share/nginx/html;
    index index.html index.htm index.php;

    # 开启Gzip全局压缩（文本类压缩60%-80%）
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
    gzip_vary on;

    # PHP统一解析 + 优化参数
    location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

        # PHP-FPM优化：减少等待超时
        fastcgi_connect_timeout 60s;
        fastcgi_send_timeout 60s;
        fastcgi_read_timeout 60s;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 128k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    # 首页通用路由
    location / {
        try_files $uri $uri/;
    }

    # api目录转发
    location /api/ {
        try_files $uri $uri/;
    }

    # 静态资源专项缓存（头像、js、css、字体）
    location ~* \.(jpg|jpeg|png|gif|webp|ico)$ {
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
        access_log off;
    }
    location ~* \.(js|css|woff|woff2|ttf)$ {
        expires 3d;
        add_header Cache-Control "public, max-age=259200";
        access_log off;
    }
}
