首页 > 其他 > 详细

flask+gunicorn+nginx部署

时间:2020-08-02 17:47:16      阅读:76      评论:0      收藏:0      [点我收藏+]

安装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

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;
    }
}

错误

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

flask+gunicorn+nginx部署

原文:https://www.cnblogs.com/sanduzxcvbnm/p/13418645.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!