upstream api_upstream {
   server web:20000;  # 使用容器名
}

# 定义 DNS 解析器
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;


server {
    listen 80;
    server_name 192.168.0.198;

    location ~ ^/api/(.*)$ {
        proxy_pass http://api_upstream/$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;
    }
}


server {
    listen 80;
    server_name www.mhaya.one;

        # 转发图片请求到 S3 存储桶
    location /avatar/ {
        proxy_pass http://mhaya-img.s3.ap-southeast-1.amazonaws.com/avatar/;
        proxy_set_header Host mhaya-img.s3.ap-southeast-1.amazonaws.com;
        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_cache_bypass $http_pragma;
        proxy_no_cache $http_pragma;
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;
    }

    location / {
        root /home/web-mobile;
        try_files $uri $uri/ /index.html;
    }

    gzip on;  # 启用gzip压缩
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;  # 指定要压缩的MIME类型
    gzip_comp_level 6;  # 压缩级别（1-9），数字越大压缩率越高，但CPU使用率也越高
    gzip_min_length 256;  # 只有当响应大小大于这个值时才进行压缩
    gzip_proxied any;  # 代理请求也进行压缩
    gzip_vary on;  # 在响应头中添加"Vary: Accept-Encoding"以确保下游缓存正确处理压缩内容
    gzip_buffers 32 16k;  # 设置缓冲区大小
    gzip_http_version 1.1;  # 设置HTTP版本
}