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

用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 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题