在 AWS EC2 上部署 Gunicorn 和 Supervisor 时出错

Error in deploy Gunicorn and Supervisor on AWS EC2

我是新手,请耐心等待

我正在尝试使用带有开放端口的 AWS Ubuntu 机器部署一个烧瓶应用程序 44380

当我 运行 使用 sudo python app.py 的 Flask 应用程序时,它可以工作。

当我尝试使用 gunicorn 时出现问题。当我使用命令

gunicorn -b 0.0.0.0:443 app:app

它推送这个错误

[2018-06-18 13:30:30 +0000] [11135] [INFO] Starting gunicorn 19.8.1
[2018-06-18 13:30:30 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:31 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:32 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:33 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:34 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:35 +0000] [11135] [ERROR] Can't connect to ('0.0.0.0', 443)

我检查过没有进程使用 lsof -i:443

监听端口 443

这里是app.py

from flask import Flask
application = Flask(__name__)

@application.route("/")
def index():
    return "Hello World!"

if __name__ == "__main__":
    application.run(host='0.0.0.0', port='443')

已编辑:通过使用 sudo -H pip install gunicorn

安装解决了 gunicorn 错误

我正在尝试在生产中部署应用程序,所以我希望它持续 运行ning。我试着 supervisor 一直保持下去

这里是supervisor

的配置
[program:app_name]
directory=/home/ubuntu/FIFA_Captcha
command=/usr/local/bin/gunicorn -b 0.0.0.0:443 app:app
autostart=true
user=root
autorestart=true
stderr_logfile=/home/ubuntu/app_name.err.log
stdout_logfile=/home/ubuntu/app_name.out.log
environment=PYTHONPATH=/usr/bin/python

输出sudo service supervisor status

Jun 18 22:02:39 ip-172-31-3-59 systemd[1]: Started Supervisor process control system for UNIX.
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,828 CRIT Supervisor running as root (no user in config file)
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,829 WARN Included extra file "/etc/supervisor/conf.d/app_name.conf" Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 INFO RPC interface 'supervisor' initialized
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 CRIT Server 'unix_http_server' running without any HTTP authenticatJun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 INFO supervisord started with pid 19562
Jun 18 22:02:40 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:40,837 INFO spawned: 'app_name' with pid 19569
Jun 18 22:02:40 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:40,952 INFO exited: app_name(exit status 3; not expected)
Jun 18 22:02:41 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:41,955 INFO spawned: 'app_name' with pid 19574
Jun 18 22:02:42 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:42,069 INFO exited: app_name(exit status 3; not expected)

来自 app_name.err.log 的输出。虽然我设置了PYTHONPATH

  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/home/ubuntu/FIFA_Captcha/app.py", line 2, in <module>
    from flask import Flask, render_template, request
ImportError: No module named flask
[2018-06-18 22:09:34 +0000] [19681] [INFO] Worker exiting (pid: 19681)
[2018-06-18 22:09:34 +0000] [19677] [INFO] Shutting down: Master
[2018-06-18 22:09:34 +0000] [19677] [INFO] Reason: Worker failed to boot.

您需要成为 root 用户才能使用端口 443。