(Python)将证书添加到服务器
我被一个问题困扰了一段时间,找不到正确的解决办法 我有一个基于瓶子(Python3)的python服务器,它是用PyCharm编写的。我正在使用“pyinstaller”将我的文件转换为一个“exe”,以便在固定PC(win7)上启动服务器。服务器可以很好地满足需要,但现在我想给它添加更多的安全性 我有一个签名证书(不是自签名)和一个密钥,我想添加它。我试图用它们启动服务器,但我不确定是否必须用它们做其他事情,因为证书没有显示在信息的主页上,网站仍然显示为“未保存” 我的普通服务器运行时使用的是:(Python)将证书添加到服务器,python,ssl,certificate,cherrypy,Python,Ssl,Certificate,Cherrypy,我被一个问题困扰了一段时间,找不到正确的解决办法 我有一个基于瓶子(Python3)的python服务器,它是用PyCharm编写的。我正在使用“pyinstaller”将我的文件转换为一个“exe”,以便在固定PC(win7)上启动服务器。服务器可以很好地满足需要,但现在我想给它添加更多的安全性 我有一个签名证书(不是自签名)和一个密钥,我想添加它。我试图用它们启动服务器,但我不确定是否必须用它们做其他事情,因为证书没有显示在信息的主页上,网站仍然显示为“未保存” 我的普通服务器运行时使用的是
from bottle import run, ...
...
if __name__ == "__main__":
...
run(host=IP, port=PORT)
run(host=IP, port=PORT, server='cherrypy', certfile='./static/MyCert.pem', keyfile='./static/key.pem')
我已经尝试了一些瓶子框架,我最终以cherrypy作为一个框架,它以一种正确的方式启动了我的服务器。
服务器正在使用以下各项运行:
from bottle import run, ...
...
if __name__ == "__main__":
...
run(host=IP, port=PORT)
run(host=IP, port=PORT, server='cherrypy', certfile='./static/MyCert.pem', keyfile='./static/key.pem')
它与当前版本的cherrypy不兼容,因此我(经过一些搜索后)将其降级为“>=3.0.8,我觉得您好像在证书中添加了密码短语。请在不使用密码短语的情况下重新生成证书,然后重试 另外,还有一点建议。我强烈建议您在nginx后面以反向代理模式运行瓶/樱桃皮服务器。这通过让nginx处理SSL会话的终止来简化您的配置,这样您的python web服务器就不需要知道任何有关证书的信息 这是我们用来终止(自签名)SSL证书并反向代理在端口9000的本地主机上运行的cherrypy站点的nginx配置的修订副本:
server {
listen example.com:80;
server_name test.example.com;
access_log /var/log/nginx/test.example.com.access.log main;
return 301 https://test.example.com$request_uri;
}
server {
listen example.com:443;
access_log /var/log/nginx/test.example.com.access.log main;
server_name test.example.com;
root /usr/local/www/test.example.com/html;
ssl on;
ssl_certificate /etc/ssl/test.example.com.crt;
ssl_certificate_key /etc/ssl/test.example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don't use SSLv3 ref: POODLE
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
client_max_body_size 16M;
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
proxy_pass http://127.0.0.1:9000;
proxy_set_header X-REAL-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}