【问题标题】:OpenSSL error - RestClient Gem - Python WSGIOpenSSL 错误 - RestClient Gem - Python WSGI
【发布时间】:2016-08-12 09:04:08
【问题描述】:
问题:
我正在努力解决 SSL 问题。我正在尝试连接到 Python 应用程序的 Web 服务器,但每次执行请求时,都会出现以下错误:
RestClient::SSLCertificateNotVerified: SSL_connect returned=1 errno=0 state=error: certificate verify failed:
详情:
- 我使用 RestClient gem (v1.8.0) 并尝试一个简单的 GET 请求
-
python code to launch the server 就是这样:
http_server = WSGIServer(('', int(port)), app, log=nylas_logger,
handler_class=NylasWSGIHandler,
keyfile='/vagrant/server.key', certfile='/vagrant/server.crt')
- 我在另一台服务器(Nginx 乘客)的另一个子域上使用相同的证书(通配符证书 COMODO),我可以成功启动我的请求
我尝试了什么:
- 我尝试使用 Brew 重新安装 Openssl
- 我成功启动了我的请求,将 verify_ssl: false 标志传递给了 restclient gem(但我想找到一个不使用此解决方法的解决方案)
- 我尝试使用 --disable-bynary 标志重新安装 Ruby(我正在使用 RVM)
- 我发起
rvm osx-ssl-certs update all
最令人惊讶的是,我实际上可以使用相同的证书在另一种类型的服务器上执行请求,因此看来问题可能出在 Python Web 服务器上。
【问题讨论】:
标签:
python
ruby
ssl
wsgi
rest-client
【解决方案1】:
原来 gevent.pywsgi 服务器没有正确处理 SSL 证书。
我安装了 Nginx 并在 localhost Python gevent.pywsgi 服务器上做了一个反向代理,并在 Nginx 部分进行了 SSL 处理,它立即工作。
有关信息,我的 nginx conf:
server{
listen 80;
return 301 https://$host$request_uri;
}
server{
listen 443;
server_name subdomain.domain.com;
ssl on;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/cert.key;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proro $scheme;
proxy_pass http://localhost:5555;
proxy_read_timeout 90;
proxy_pass_request_headers on;
proxy_redirect http://localhost:5555 https://subdomain.domain.com;
}
}
并且我将 python 服务器限制为仅侦听 localhost 请求。