【问题标题】:Flask app port refusing connection on ec2 [duplicate]烧瓶应用程序端口拒绝ec2上的连接[重复]
【发布时间】:2020-06-20 19:23:42
【问题描述】:

我有一个烧瓶应用程序,我将其部署在 EC2 实例上。该应用程序启动正常:

ubuntu@ip-something:~/webservices$ python service/texting_service.py 
 * Serving Flask app "texting_service" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 146-396-474

当我 ssh 进入此 EC2 实例并使用 localhost 调用服务时,它会返回预期的响应。但是,当我尝试使用实例的公共 IP 地址从 EC2 实例外部调用此服务时,我看到此错误:

curl: (7) Failed to connect to ec2.instance.ip.address port 8080: Connection refused

我确认我已为附加到此 EC2 实例的安全组打开入口端口 8080。我错过了什么?

【问题讨论】:

    标签: flask amazon-ec2 aws-security-group


    【解决方案1】:

    我想通了。如果您没有在app.run() 函数中传递带有值0.0.0.0 的参数host,则应用程序在外部不可见。执行以下操作解决了我的问题:

    if __name__ == '__main__':
        app.run(host='0.0.0.0')
    

    【讨论】:

    • 这就是我所缺少的。谢谢
    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多