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

用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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序