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记录
折腾挺久了,还是没搞明白,求教是哪一步出了问题?万分感谢!

怪我咯
怪我咯

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

全部回复(5)
黄舟

试试下面的排除步骤:

  • 1.guicorn跑起来没? curl 127.0.0.1:5000 看看有页面输出吗

  • 2.nginx跑起来没有? nmap 外网IP 看看80是否开着

  • 3.dns起效没有? nslookup noorders.com 看看是否正确解析到你的服务器外网IP了

  • 4.nginx和域名是否对上了?curl noorders.com 看输出以及nginx的access.log

  • 5.flask用guicorn跑的时候是否有IP白名单之类的限制

  • 6.看nginx和guicorn的access.log、error.log。

另外可以先把guicorn关了,直接python -m SimpleHTTPServer 5000直接在5000跑一个HTTP服务,看看能正常访问不,能访问的话至少说明nginx和dns是对的,问题就有可能出现在guicorn和flask上了。

多用排除法吧。。

天蓬老师

在/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 不大对

ringa_lee

把http://127.0.0.1:5000 改成http://127.0.0.1:5000/

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

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