weixin_41048155
搂着先生小蛮腰
采纳率0%
2019-12-04 11:11

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

80

用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_ dominic123_ 1月前

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

    点赞 评论 复制链接分享
  • zqbnqsdsmd zqbnqsdsmd 2年前
    点赞 评论 复制链接分享