在 web.py 中用阿里云的免费证书设置https访问

网友发帖问,所以有此实践。

环境:Debian9,python2.7

过程:

1.pip install web.py # 安装 web.py,本例版本是 web.py-0.39
webpy-1.png

2.pip install pyOpenSSL # 还需安装这个包
webpy-2.png

3.vi test.py # 创建测试文件,内容如下:(请替换相应的ssl证书存储路径)

import web
from web.wsgiserver import CherryPyWSGIServer

CherryPyWSGIServer.ssl_certificate = "/root/swas.anqun.org.pem"
CherryPyWSGIServer.ssl_private_key = "/root/swas.anqun.org.key"

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'

if __name__ == "__main__":
    app.run()

webpy-3.png

4.python test.py # 运行测试,默认在8080端口上
webpy-4.png

5.在浏览器里访问,如本例,https://swas.anqun.org:8080,正常
webpy-5.png

参考:http://webpy.org/cookbook/ssl

标签: python

添加新评论