解决openresty发送https请求时 lua ssl certificate verify error lua ssl certificate verify error: (20: unable to get local issuer certificate)问题。发送请求前需要给lua指定一个受信任的证书。
lua请求:
function _M.http_get(self, url, timeout) local http = require "resty.http" local httpc = http.new() timeout = timeout or 30000 httpc:set_timeout(timeout) local res, err = httpc:request_uri(url, { method = "GET", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) httpc:set_keepalive(5000, 100) --httpc:close() return res,err end ---example local weUrl = 'https://api.weixin.qq.com/sns/jscode2session' local res, _err = _M:http_get(weUrl, 15000)
一、给lua指定证书
# fix lua ssl certificate verify error lua ssl certificate verify error: (20: unable to get local issuer certificate) #bash yum install ca-certificates update-ca-trust cp /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-lua.pem #Nginx.conf lua_ssl_verify_depth 2; lua_ssl_trusted_certificate '/etc/ssl/certs/ca-lua.pem';
二、遇到的其他问题解决
#nginx.conf resolver 223.5.5.5 223.6.6.6 1.2.4.8 114.114.114.114 8.8.8.8 valid=3600s;
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明。