nginx-block-sensitive-paths.conf 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. # === 拒绝敏感路径扫描(减少日志噪音)===
  2. # 放在 server {} 块内,其他 location 之前
  3. # 环境配置文件扫描
  4. location ~* ^/\.env {
  5. default_type application/json;
  6. return 403 '{"code":403,"message":"Forbidden"}';
  7. }
  8. location ~* ^/api/\.env {
  9. default_type application/json;
  10. return 403 '{"code":403,"message":"Forbidden"}';
  11. }
  12. # Spring Boot Actuator
  13. location ~* ^/actuator {
  14. default_type application/json;
  15. return 404 '{"code":404,"message":"Not Found"}';
  16. }
  17. # Git 文件泄露
  18. location ~* ^/\.git {
  19. default_type application/json;
  20. return 403 '{"code":403,"message":"Forbidden"}';
  21. }
  22. # 常用扫描路径(返回 404 伪装不存在)
  23. location ~* ^/(admin|wp-admin|wp-content|wp-includes|xmlrpc|phpmyadmin|pma|manager|console|debug|swagger|api-docs|docs)(/|$) {
  24. return 404;
  25. }
  26. # 通用:以点开头的隐藏文件
  27. location ~* /\.(?!well-known) {
  28. default_type application/json;
  29. return 403 '{"code":403,"message":"Forbidden"}';
  30. }