| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- server {
- listen 80;
- server_name localhost;
- # 根目录配置
- root /usr/share/nginx/html;
- index index.html;
- # 禁用缓存,便于开发和调试
- add_header Cache-Control "no-cache, no-store, must-revalidate";
- add_header Pragma "no-cache";
- add_header Expires "0";
- # 健康检查端点
- location /health {
- access_log off;
- return 200 "healthy\n";
- add_header Content-Type text/plain;
- }
- # 静态资源配置(带缓存)
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
- expires 1y;
- add_header Cache-Control "public, immutable";
- add_header Access-Control-Allow-Origin "*";
- }
- # 反向代理到API网关
- location /api/ {
- proxy_pass http://localhost: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_read_timeout 30s;
- proxy_connect_timeout 10s;
- }
- # Vue Router SPA 配置 - 所有非API请求都返回 index.html
- location / {
- try_files $uri $uri/ /index.html;
- }
- # 禁用特定文件访问
- location ~ /\. {
- deny all;
- access_log off;
- log_not_found off;
- }
- location ~ ~$ {
- deny all;
- access_log off;
- log_not_found off;
- }
- # 错误页面配置
- error_page 404 /index.html;
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root /usr/share/nginx/html;
- }
- # 日志配置
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log warn;
- }
|