# Nginx配置文件 - 测试环境 # 用于Vue3前端静态文件服务和API代理 server { listen 80; server_name staging.anxin.com localhost; # 测试环境日志配置 access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log warn; # 安全响应头 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 Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self'" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()" always; # 静态文件服务 location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; # 测试环境缓存配置 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1d; add_header Cache-Control "public, immutable"; } location ~* \.(html)$ { expires 1h; add_header Cache-Control "public"; } } # API代理到后端服务 location /prod-api/ { proxy_pass http://anxin-backend:8080/; 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 30s; proxy_read_timeout 30s; proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; # 限制请求大小 client_max_body_size 10m; } # 健康检查端点 location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # 测试环境状态页面 location /nginx_status { stub_status on; access_log off; allow 172.22.0.0/16; deny all; } }