nginx-okr-performance.conf 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # ============================================================
  2. # Nginx 反向代理配置 — OKR 绩效考核系统
  3. # 用途: HTTPS 终端 + 安全头 + 反向代理到 Spring Boot
  4. # 部署: cp okr-performance.conf /etc/nginx/sites-available/ && ln -s /etc/nginx/sites-enabled/
  5. # ============================================================
  6. # 上游服务 — Spring Boot 绑定 127.0.0.1:18080(不对外暴露)
  7. upstream okr_backend {
  8. server 127.0.0.1:18080 fail_timeout=10s;
  9. keepalive 32;
  10. }
  11. # HTTP → HTTPS 强制跳转
  12. server {
  13. listen 80;
  14. server_name okr.your-company.com;
  15. return 301 https://$host$request_uri;
  16. }
  17. # HTTPS 主服务
  18. server {
  19. listen 443 ssl http2;
  20. server_name okr.your-company.com;
  21. # ===== TLS 证书(使用 certbot 自动管理) =====
  22. # 首次获取: certbot --nginx -d okr.your-company.com
  23. ssl_certificate /etc/letsencrypt/live/okr.your-company.com/fullchain.pem;
  24. ssl_certificate_key /etc/letsencrypt/live/okr.your-company.com/privkey.pem;
  25. # ===== TLS 安全配置 =====
  26. ssl_protocols TLSv1.2 TLSv1.3;
  27. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
  28. ssl_prefer_server_ciphers on;
  29. ssl_session_cache shared:SSL:10m;
  30. ssl_session_timeout 10m;
  31. # HSTS — 强制浏览器使用 HTTPS(1年,含子域)
  32. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  33. # ===== 安全响应头 =====
  34. add_header X-Content-Type-Options "nosniff" always;
  35. add_header X-Frame-Options "DENY" always;
  36. add_header X-XSS-Protection "1; mode=block" always;
  37. add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  38. add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
  39. # CSP — 内容安全策略(根据实际需求调整)
  40. add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'" always;
  41. # ===== 日志(可选:采样以减少磁盘写入) =====
  42. access_log /var/log/nginx/okr-access.log combined buffer=16k;
  43. error_log /var/log/nginx/okr-error.log warn;
  44. # 请求体大小限制(上传文件等)
  45. client_max_body_size 10m;
  46. # ===== 反向代理 =====
  47. location / {
  48. proxy_pass http://okr_backend;
  49. proxy_http_version 1.1;
  50. # WebSocket / 长连接支持
  51. proxy_set_header Upgrade $http_upgrade;
  52. proxy_set_header Connection "upgrade";
  53. # 传递真实客户端信息
  54. proxy_set_header Host $host;
  55. proxy_set_header X-Real-IP $remote_addr;
  56. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  57. proxy_set_header X-Forwarded-Proto $scheme;
  58. # 超时设置
  59. proxy_connect_timeout 30s;
  60. proxy_read_timeout 60s;
  61. proxy_send_timeout 30s;
  62. # 缓冲设置
  63. proxy_buffering on;
  64. proxy_buffer_size 4k;
  65. proxy_buffers 8 16k;
  66. }
  67. # 屏蔽敏感路径
  68. location ~ /\. {
  69. deny all;
  70. return 404;
  71. }
  72. # 健康检查端点(可选)
  73. location /health {
  74. proxy_pass http://okr_backend/actuator/health;
  75. access_log off;
  76. }
  77. }