server { listen 80; server_name localhost; # 基础设置 root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; client_max_body_size 100m; # 错误页面配置 error_page 500 502 503 504 /50x.html; location = /50x.html { internal; # 仅用于内部错误请求 } # Gzip 压缩设置 gzip on; gzip_min_length 1k; gzip_comp_level 6; gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; gzip_vary on; gzip_disable "MSIE [1-6]\."; # 静态资源缓存优化 location ~* \.(jpg|jpeg|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } # API 代理配置 location /api/ { proxy_pass http://learn-archives-api-svc:8080/api/; 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_connect_timeout 30s; proxy_send_timeout 60s; proxy_read_timeout 60s; proxy_buffering on; } }