nginx从雷池Waf反向代理获取真实ip

1.先创建两个静态页面

2.配置nginx.conf,1.com用默认配置,2.com获取X-Forwarded-Host、 X-Forwarded-Proto字段并使用自定义的log格式记录。

server {
    listen 8081;  # 监听端口为8081
    server_name 1.com;

    root /var/www/html/;
    index 1.html;

    # 允许192.168.80.128访问1.com
    allow 192.168.80.128;
    deny all;

    location / {
        try_files $uri $uri/ /1.html =404;
        # 如果请求不是192.168.80.128,返回403 Forbidden
        if ($remote_addr != 192.168.80.128) {
            return 403;
        }
    }
}


server {
   
    listen 8082;
    server_name 2.com;

    root /var/www/html/;
    index 2.html;

  
    # 在location块中使用定义的log_format
    location / {
        try_files $uri $uri/ /2.html =404;
        add_header X-Forwarded-Host $host;
        add_header X-Forwarded-Proto $scheme;
        access_log /var/log/nginx/2.com_access.log combined_extended;
    }

    
}

3.注意在http块中加入

        log_format combined_extended '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_x_forwarded_host" "$http_x_forwarded_proto" '
        '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';   sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;

4.配置雷池

5.修改host

6.访问并查看日志

这是1.com的

这是2.com的,加入了真实ip

1.com可以通过雷池访问而不可以通过ip+端口访问

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值