nginx.conf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. server {
  2. listen 80;
  3. server_name math-questions.chunsunqiuzhu.com;
  4. # 重定向 HTTP 到 HTTPS
  5. return 301 https://$server_name$request_uri;
  6. }
  7. server {
  8. listen 443 ssl http2;
  9. server_name math-questions.chunsunqiuzhu.com;
  10. # SSL 证书配置
  11. ssl_certificate /etc/nginx/ssl/cert.pem;
  12. ssl_certificate_key /etc/nginx/ssl/key.pem;
  13. # SSL 优化配置
  14. ssl_protocols TLSv1.2 TLSv1.3;
  15. ssl_ciphers HIGH:!aNULL:!MD5;
  16. ssl_prefer_server_ciphers on;
  17. ssl_session_cache shared:SSL:10m;
  18. ssl_session_timeout 10m;
  19. # 安全头
  20. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  21. add_header X-Frame-Options "SAMEORIGIN" always;
  22. add_header X-Content-Type-Options "nosniff" always;
  23. add_header X-XSS-Protection "1; mode=block" always;
  24. # 日志
  25. access_log /var/log/nginx/access.log;
  26. error_log /var/log/nginx/error.log;
  27. # 反向代理到应用
  28. location / {
  29. proxy_pass http://math-questions:8100;
  30. proxy_set_header Host $host;
  31. proxy_set_header X-Real-IP $remote_addr;
  32. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  33. proxy_set_header X-Forwarded-Proto $scheme;
  34. # WebSocket 支持(如果需要)
  35. proxy_http_version 1.1;
  36. proxy_set_header Upgrade $http_upgrade;
  37. proxy_set_header Connection "upgrade";
  38. # 超时设置
  39. proxy_connect_timeout 300s;
  40. proxy_send_timeout 300s;
  41. proxy_read_timeout 300s;
  42. }
  43. # 静态文件缓存(如果有)
  44. location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  45. proxy_pass http://math-questions:8100;
  46. expires 30d;
  47. add_header Cache-Control "public, immutable";
  48. }
  49. }