nginx openresty异常处理小记,nginxopenresty


最近刚换工作,新公司作为一资讯公司有为客户提供相关SDK去接入公司系统进行一些信息查询作业。随之请求流量的增加,缺少网关层进行API保护,系统常常会因为流量暴增时间段搞垮。自然而然,作为招入公司重构原有系统职责中的开发计划的第一步自然就是打算先做网关了。之前主要是做Java开发,对Openresty做涉及到相关技术见解都很肤浅(欢迎大家拍砖),对中间学习使用Openresty所遇到一些异常在这里做个小记 。(持续更新中…)

模块:Resty_Lua_Http

发起SSL请求异常: 20: unable to get local issuer certificate

示例:

local http = require("resty.http")

local httpc = http.new()

local resp, err = httpc:request_uri("https://m.taobao.com", {
    method = "GET",
    path = "/#index",
    headers = {
        ["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"
    },
})

if not resp then
    ngx.say("request error:", err)
    return
end

原因:nginx没有获得本地颁发者证书
解决方法:在nginx.conf http -> server 加入已安装OpenSSL根证书地址,见第(6,7行)

server {
    listen 8000;
    server_name _;
    resolver 8.8.8.8;
    --
    lua_ssl_verify_depth 2;
    lua_ssl_trusted_certificate /etc/ssl/certs/GlobalSign_Root_CA.pem;
    ---
    location /api {
        default_type "text/html";
        lua_code_cache off;
        content_by_lua_file /home/hf/IdeaProjects/apigateway/lua/http.lua;
    }
}

相关内容

    暂无相关文章