nginx.conf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. upstream backend {
  2. server 127.0.0.1:8000;
  3. keepalive 64;
  4. }
  5. server {
  6. listen 80;
  7. server_name _;
  8. return 301 https://$host$request_uri;
  9. }
  10. server {
  11. listen 443 ssl http2;
  12. server_name your-domain.com;
  13. ssl_certificate /etc/nginx/ssl/cert.pem;
  14. ssl_certificate_key /etc/nginx/ssl/key.pem;
  15. ssl_protocols TLSv1.2 TLSv1.3;
  16. ssl_ciphers HIGH:!aNULL:!MD5;
  17. client_max_body_size 50m;
  18. # Gzip
  19. gzip on;
  20. gzip_vary on;
  21. gzip_min_length 1024;
  22. gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
  23. # 安全头
  24. add_header X-Frame-Options "SAMEORIGIN" always;
  25. add_header X-Content-Type-Options "nosniff" always;
  26. add_header X-XSS-Protection "1; mode=block" always;
  27. # API 反向代理
  28. location /api/ {
  29. proxy_pass http://backend;
  30. proxy_http_version 1.1;
  31. proxy_set_header Host $host;
  32. proxy_set_header X-Real-IP $remote_addr;
  33. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  34. proxy_set_header X-Forwarded-Proto $scheme;
  35. proxy_set_header Connection "";
  36. # SSE 支持:禁用缓冲
  37. proxy_buffering off;
  38. proxy_cache off;
  39. proxy_read_timeout 300s;
  40. # 限流
  41. limit_req zone=api_limit burst=20 nodelay;
  42. }
  43. # 健康检查
  44. location /health {
  45. proxy_pass http://backend;
  46. access_log off;
  47. }
  48. # 管理后台
  49. location /admin {
  50. alias /var/www/admin/dist;
  51. try_files $uri $uri/ /admin/index.html;
  52. index index.html;
  53. }
  54. }
  55. # 限流区域定义
  56. limit_req_zone $binary_remote_addr zone=api_limit:10m rate=60r/m;