参考资料

  1. OpenResty编译安装详细说明以及案例
  2. Nginx集群负载(基于LVS和Keepalived)搭建详细说明以及案例
  3. Nginx upstream容错机制详解详细说明以及案例
  4. nginx 配置域名
  5. 检测Nginx配置文件 nginx -t
  6. 如何配置Nginx反向代理?
  7. Nginx TCP/UDP代理详细说明以及案例
  8. Nginx如何支持动态内容?
  1. 安装Nginx和WAF模块

    • 安装Nginx

    • 添加ModSecurity模块(如LibModSecurity)

  2. 配置WAF规则

    • 使用OWASP核心规则集(CRS)

    • 示例配置片段:

      modsecurity_rules_file /etc/nginx/modsec/main.conf;
      modsecurity on;
  3. Nginx安全加固配置

    • 禁用服务器令牌:

      server_tokens off;
    • 设置安全头部:

      add_header X-Frame-Options "SAMEORIGIN";
      add_header X-Content-Type-Options "nosniff";
  4. 限制请求处理

    • 限制请求大小:

      client_max_body_size 10m;
    • 限制请求方法:

      if ($request_method !~ ^(GET|POST|HEAD)$) {
          return 444;
      }
  5. 日志监控

    • 配置ModSecurity审计日志:

      SecAuditLog /var/log/nginx/modsec_audit.log
  6. 示例完整配置

    server {
        listen 80;
        modsecurity on;
        modsecurity_rules_file /etc/nginx/modsec/main.conf;
        
        location / {
            proxy_pass http://backend;
            modsecurity_rules_file /etc/nginx/modsec/crs-setup.conf;
            modsecurity_rules_file /etc/nginx/modsec/rules/*.conf;
        }
    }

声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。