flask+gunicorn+nginx部署
安装nginx和gunicorn
yum install nginx
pip3 install gunicorn
flask项目配置
#main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'hello world'
if __name__ == '__main__':
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
app.run()
gunicorn配置
# main是main.py的文件名
/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:5000 main:app --reload --timeout 600 --daemon
nginx配置
server {
listen 80;
server_name ip或域名;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
}
}
错误
2020/08/02 04:52:18 [crit] 27772#0: *1 connect() to 127.0.0.1:5000 failed (13: Permission denied) while connecting to upstream, client: xxxxx, server: xxxxx, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "xxxxx"
解决办法:关闭selinux