使用NGINX代理隐藏客户端IP

dxxyhpgq  于 2023-04-20  发布在  Nginx
关注(0)|答案(1)|浏览(228)

尝试访问一个远程资源,该资源在某些国家/地区的IP地址上有一个块。因此,我想到使用NGINX作为代理来隐藏浏览器的IP地址,并通过显示不同的IP地址来请求资源。我的配置似乎不起作用,远程资源通过某种方式识别浏览器的地址来阻止访问。

set_real_ip_from 176.9.0.1/24;  #  nginx server ip range
real_ip_header X-Real-IP;
real_ip_recursive on;

location /test/ {
    rewrite ^\/test\/(.*) /$1 break;
    proxy_pass  https://remote.blocked.biz;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        Host         remote.blocked.biz   ;
    proxy_set_header Authorization "";
    proxy_ssl_server_name on;
    proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

}

t3irkdon

t3irkdon1#

我最近也面临着同样的问题,我是这样做的:

server {
    listen       443 ssl;
    server_name  balabala.example.com;

    ssl_certificate /root/.acme.sh/balabala.example.com_ecc/fullchain.cer;
    ssl_certificate_key /root/.acme.sh/balabala.example.com_ecc/reddwarf.life.key;

    location / {
        client_max_body_size 1m;
        proxy_redirect off;
        set_real_ip_from 92.210.23.237;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $host;
        proxy_set_header X-Forwarded-For 92.210.23.237;
        real_ip_header X-Forwarded-For;
        proxy_read_timeout 3600;
        proxy_pass http://127.0.0.1:8001;
    }
}

然后在后端使用这个Python代码来获取真实的ip(检查ip替换成功):

@router.get("/v1/stream")
def do_stream(q: str, authorization: str = Header(None), request: Request = None):
    client_host = request.client.host

你会发现真实的的IP被替换了。

相关问题