【发布时间】:2020-05-26 18:57:59
【问题描述】:
我创建了一个烧瓶应用程序。我正在尝试在 Centos 7 中使用 WSGI Gunicorn 服务器和 Nginx 反向代理将其部署到生产环境中。以下是我的项目工作目录。
projet
|--templates
|--static
|---app.py
|---wsgi.py
这里我使用的是虚拟环境“my_app”。当我要去项目工作文件夹并运行应用程序时
gunicorn wsgi:app
我可以在网页中看到结果。但是当我关闭系统时,我得到了502 Bad GateWay。这意味着每次我需要手动运行 gunicorn 命令才能在网页中看到结果。但我想自动启动它。为此,我在 systemd 的帮助下创建了一个服务文件。以下是 Nginx 和 Gunicorn 的配置文件。
在 /etc/nginx/sites-enabled/flaskapp.conf 中
server{
listen 80;
server_name xxxx.xxx.xx.xx;
access_log /var/log/nginx/error.log;
uwsgi_read_timeout 120;
location = /favicon.ico { access_log off; log_not_found off; }
location / {
proxy_pass http://unix://home/centos/Python-3.6.4/my_flask_app/pre_owned_model/evaluation_calculator/gunicorn.sock;
#proxy_pass http://127.0.0.1:8000;
}
}
在 /etc/systemd/system/gunicorn.service 中
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
Type=simple
User=centos
Group=centos
RuntimeDirectory=gunicorn
WorkingDirectory=/home/centos/Python-3.6.4/my_flask_app/pre_owned_model/evaluation_calculator
ExecStart=/home/centos/Python-3.6.4/my_flask_app/my_app/bin/gunicorn --workers 3 --bind unix:/home/centos/Python-3.6.4/my_flask_app/pre_owned_model/evaluation_calculator/gunicorn.sock -m 007 wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
TimeoutStopSec=3
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
但是,我没有得到预期的结果。每次我得到502 Bad Gateway,即使在创建服务之后也是如此。谁能解释我如何实现这一目标。
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
你能出示你对应的
/etc/systemd/system/gunicorn.socket文件吗? -
嗨,当我重新加载 systemctl 时,gunicorn.socket 文件完全为空。
标签: python-3.x nginx flask centos gunicorn