nginx配置关闭ipv6

文章详细描述了一个使用Lua脚本对BaiduOCRAPI进行代理转发的过程,包括设置resolver、处理IPv6和X-Forwarded-Proto等头信息,确保通过代理访问API并传递access_token。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# 关键代码
resolver 服务器dns(可以多个) valid=5 ipv6=off;
# 关键代码
set $skyneturl "https://aip.baidubce.com";
location /xxxx/baidu/rest/2.0/ocr/v1/business_license {
    lua_need_request_body on;
    log_escape_non_ascii off;

    body_filter_by_lua '
        local resp_body = string.sub(ngx.arg[1], 1, 1000)
        ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
        if ngx.arg[2] then
            ngx.var.resp_body = ngx.ctx.buffered
        end
    ';
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 150;
                proxy_send_timeout 150;
                #转发地址
 #   proxy_pass https://aip.baidubce.com/;
 # 关键代码
    proxy_pass $skyneturl/baidu/rest/2.0/ocr/v1/business_license?$args;
}

请求地址:http://localhost:port/xxxx/baidu/rest/2.0/ocr/v1/business_license?access_token=465465416

注意:resolver 结合set 才好使 不知道为啥

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值