server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # 统一以 UTF-8 返回文本。字符集由 charset 指令加到各资源自身的 MIME 类型上, # 不能再 add_header Content-Type,否则会把 js/css 的 MIME 也覆盖成 text/html。 charset utf-8; # Gzip compression gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml; # Handle Vue Router (SPA) location / { try_files $uri $uri/ /index.html; } # API proxy to backend location /api/ { proxy_pass http://backend:8082/api/; proxy_http_version 1.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; } # WebSocket support location /ws { proxy_pass http://backend:8082/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_read_timeout 86400; } # Uploaded files location /uploads/ { proxy_pass http://backend:8082/uploads/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # Static assets caching location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; } }