nginx openresty異常處理小記

最近剛換工作,新公司作爲一資訊公司有爲客戶提供相關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;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章