搂着先生小蛮腰 2019-12-04 11:11 采纳率: 0%
浏览 2400
已结题

用openresty(nginx+lua)框架开发的项目实现接入统一认证功能,发请求拿token报xxxxx.com.cn could not be resolved (110: Operation timed out)

用openresty(nginx+lua)框架开发的项目实现接入统一认证功能(oauth2),发请求拿access-token时报xxxxx.com.cn could not be resolved (110: Operation timed out),同样的代码在centos,ubuntu虚拟机上测试时能成功运行并返回正确结果,把代码部署到centos服务器上就不行了

nginx部分配置如下

resolver 114.114.114.114 8.8.8.8 8.8.4.4;
    include mime.types;
    server {
        listen 80;
    lua_ssl_verify_depth 10;
        lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
    set $resp_body "";
    set $arg_accessToken "";
        lua_need_request_body on;
        include location_aies.conf;
    }

oauth部分配置如下(在虚拟机中ip用localhost代替)

oauth_callback_url = 'http://10.xx.1xx.xx:80/oauth/callback'

获得code后去拿access_token的代码如下

local function request_access_token(code)
    --ngx.log(ngx.ERR, 'Requesting access token with code ' .. code)
    local httpc = http.new()
    httpc:set_timeout(7000)
    local payload = {
        client_id=client_id,
        grant_type="authorization_code",
        client_secret=client_secret,
        code=code }
    local params = { headers = {
          ["Content-Type"] = "application/x-www-form-urlencoded",
        }, method="POST",body=ngx.encode_args(payload) }
    local url=access_token_uri
    local res, err = httpc:request_uri(url, params)
    if err then
       **ngx.log(ngx.ERR, "Got error during access token request: " .. err)**
        ngx.header['Content-type'] = 'text/html'
        ngx.status = ngx.HTTP_FORBIDDEN
        ngx.say("Got error during access token request: " .. err)
        return ngx.exit(ngx.HTTP_FORBIDDEN)
    else

就是这这段代码报错的,返回err,err信息为:Got error during access token request:xxxx.com.cn could not be resolved (110: Operation timed out)

我花了好久的时间都没解决,麻烦各路大神指点一下,谢谢了

  • 写回答

2条回答 默认 最新

  • dominic123_ 2021-03-02 20:04
    关注

    老哥有找到对应的解决方案吗,我也遇到相同的问题找了好久还没解决。

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献