python - flask+gunicorn+nginx部署失败原因?
怪我咯
怪我咯 2017-04-17 17:44:34
[Python讨论组]

尝试用gunicorn+nginx组合在AWS部署一个flask应用,不知道为啥老是不成功。。求助
nginx配置

/etc/nginx/sites-available/default

server {
        listen   80  ;

        server_name noorders.com ;

        root /home/The-Garden-of-Forking-Paths/  ;
        access_log  /home/The-Garden-of-Forking-Paths/log/nginx.log ;
        error_log  /home/The-Garden-of-Forking-Paths/log/nginx.err  ;

        location / {
                proxy_pass http://127.0.0.1:5000  ;
                proxy_redirect off  ;
                proxy_set_header Host $host  ;
                proxy_set_header X-Real-IP $remote_addr  ;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for  ;
            }
        location /static/ {
                alias /home/The-Garden-of-Forking-Paths/app/static/;
            }
        }

运行命令sudo service nginx start

gunicorn的配置文件为

/home/The-Garden-of-Forking-Paths/project.conf

workers = 4
bind = '127.0.0.1:5000'
proc_name = 'manage'
pidfile = '/tmp/app.pid' 

运行命令 gunicorn --config project.conf manage:app

域名服务商是Godaddy
DNS解析换成了DNSPod
AWS的弹性IP已经加入域名的A记录
折腾挺久了,还是没搞明白,求教是哪一步出了问题?万分感谢!

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(3)
天蓬老师

在/etc/nginx/sites-available/default里server上面加入这段试试:

upstream noorders.com {
       server 127.0.0.1:5000;
    }
    

我也是前两天刚弄的新手,不确定这样行不行,试一下?

迷茫

gunicorn 的 bind = '127.0.0.1:5000' 改成 bind = '0.0.0.0:5000' 试试。

怪我咯

感觉 proxy_redirect off 不大对

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号