I use Flask as Web Application, to redirect http to https, I added such codes in app.py:
@app.before_request def before_request(): if request.url.startswith('http://'): url = request.url.replace('http://', 'https://', 1) return redirect(url, code=301) if __name__ == '__main__': app.run() and the gunicorn command in supervisor.conf is:
command=/home/MyToDo/venv/bin/gunicorn --certfile=/home/MyToDo/SSL/mytodo.vip.cer --keyfile=/home/MyToDo/SSL/mytodo.vip.key -w3 -b0.0.0.0:443 -b0.0.0.0:80 app:app but when I visit the website, I still need to add "https://" in front the url, it didn't redirect automaticly. So how to make gunicorn redirect http to https, does using Nginx is the only way?