简体   繁体   English

如何通过HTTPS运行python-socketio(eventlet WSGI服务器)

[英]How to run python-socketio (eventlet WSGI server) over HTTPS

I want to run the following eventlet WSGI server over HTTPS. 我想通过HTTPS运行以下eventlet WSGI服务器。 I am trying to connect to the python server from JavaScript on my HTTPS enabled web-server. 我正在尝试在启用HTTPS的Web服务器上从JavaScript连接到python服务器。

I would like the answer to describe how I would change this code below to work with HTTPS. 我想要答案来描述如何更改下面的代码以使用HTTPS。

import socketio
import eventlet
import eventlet.wsgi
from flask import Flask, render_template

sio = socketio.Server()
app = Flask(__name__)

@app.route('/')
def index():
    """Serve the client-side application."""
    return render_template('index.html')

@sio.on('connect', namespace='/chat')
    def connect(sid, environ):
    print("connect ", sid)

@sio.on('chat message', namespace='/chat')
def message(sid, data):
    print("message ", data)
    sio.emit('reply', room=sid)

@sio.on('disconnect', namespace='/chat')
def disconnect(sid):
    print('disconnect ', sid)

if __name__ == '__main__':
    # wrap Flask application with engineio's middleware
    app = socketio.Middleware(sio, app)

    # deploy as an eventlet WSGI server
    eventlet.wsgi.server(eventlet.listen(('', 8000)), app)

This code was take from here 这段代码是从这里拿来的

To run a Evenlet WSGI server over HTTPS all that's needed is to pass an SSL-wrapped socket to the server() method like so: 要通过HTTPS运行Evenlet WSGI服务器,所需要做的就是将SSL封装的套接字传递给server()方法,如下所示:

wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', 8000)),
                          certfile='cert.crt',
                          keyfile='private.key',
                          server_side=True),
        app)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM