🌐

flask https 설정

Tags
Python
ID matched
Created
Mar 15, 2023 11:44 PM
Last Updated
Last updated July 15, 2023
 
 
 

1. flask 예제 (http)

from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '<h1>This is HTTP site</h1>' if __name__ == '__main__': app.run('0.0.0.0', 9999, debug=True)
notion image
 

2. 인증서 생성

openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
notion image
 
 

3. flask 예제 (https)

from flask import Flask import eventlet import eventlet.wsgi app = Flask(__name__) @app.route('/') def hello(): return '<h1>This is HTTPS site</h1>' if __name__ == '__main__': server = eventlet.wrap_ssl(eventlet.listen(('0.0.0.0', 9999)), certfile='secrets/cert.pem', keyfile='secrets/key.pem', server_side=True) eventlet.wsgi.server(server, app)
notion image