web.py设置HTTPS协议

Attila Nagy  HTTPS in web.py  [reviewed]  <hh/1344>  (2010-08-27)  Children: -
Using HTTPS in web.py is easy (provided you have your certificates).
Just import the WSGI server class from web.py at the beginning of
src/hkweb.py:

    from web.wsgiserver import CherryPyWSGIServer

Then, add this code to the beginning of hkweb.start():

    CherryPyWSGIServer.ssl_certificate = "/path/to/your.crt"
    CherryPyWSGIServer.ssl_private_key = "/path/to/your.key"

And that's all. From now on, you can access hkweb via https://localhost:8080.

If you need a certificate, use this:

    openssl genrsa -des3 -out server.key 1024
    openssl req -new -key server.key -out server.csr
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    mv server.key myserver.key
    mv server.crt myserver.crt

Your browser will warn you about the certificate being invalid, but it
will work nonetheless.

The relevant Google Groups thread:

http://groups.google.com/group/webpy/browse_thread/thread/53a7cdc07af6fcc5
# coding=utf-8


# @Author : zhoujiamu
# @Time   : 2018/2/8 22:37




import web


urls = ('/.*','WebHooks')
app = web.application(urls, globals())


class WebHooks:
    def POST(self):
        raw_payload = web.data()
        json_encode = json.loads(raw_payload)


if __name__ == '__main__':
    #app.run()


    from web.wsgiserver import CherryPyWSGIServer


    ssl_cert = '/usr/ssl/server.crt'
    ssl_key = '/usr/ssl/server.key'
    CherryPyWSGIServer.ssl_certificate = ssl_cert
    CherryPyWSGIServer.ssl_private_key = ssl_key
    app.run()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值