【问题标题】:run Gunicorn with WSGI inside a folder在文件夹中使用 WSGI 运行 Gunicorn
【发布时间】:2020-08-30 20:27:08
【问题描述】:

我的项目结构如下。我使用文件夹将所有设置文件放入其中。

~/myproject/
           - env
           - server
                 - api
                 - home
                     - settings
                         - dev.py
                         - prod.py
                     - wsgi
                         - dev.py
                         - prod.py

myproject/server/home/wsgi/dev.py 是:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings.dev")

application = get_wsgi_application()

myproject/server/home/settings/dev.py 里面还有:

WSGI_APPLICATION = 'home.wsgi.dev.application'

通过上述所有设置,服务器可以完美运行。当我尝试部署和运行 gunicorn 时,它只是失败了。这是我的 gunicorn.service:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=demouser
Group=www-data
WorkingDirectory=/home/demouser/myproject
ExecStart=/home/demouser/myproject/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/demouser/myproject.sock home.wsgi.dev:application


[Install]
WantedBy=multi-user.target

我不确定为什么我会收到此错误,因为 gunicorn 永远不会启动:

 Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-08-30 05:04:48 UTC; 14min ago
  Process: 13354 ExecStart=/home/demouser/myproject/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/
 Main PID: 13354 (code=exited, status=203/EXEC)

Aug 30 05:04:48 localhost systemd[1]: Started gunicorn daemon.
Aug 30 05:04:48 localhost systemd[13354]: gunicorn.service: Failed to execute command: No such file or directory
Aug 30 05:04:48 localhost systemd[13354]: gunicorn.service: Failed at step EXEC spawning /home/demouser/myproject/env/
Aug 30 05:04:48 localhost systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Aug 30 05:04:48 localhost systemd[1]: gunicorn.service: Failed with result 'exit-code'.
~

我希望我为每个人都说清楚了。谢谢

【问题讨论】:

    标签: python django gunicorn


    【解决方案1】:

    我已经解决了,如果你有兴趣,这里是:

    我已经安装了 Gunicorn3,然后我更改了 gunicorn.service 文件并编辑了这些行:

    WorkingDirectory=/home/demouser/myproject/server
    ExecStart=/usr/bin/gunicorn3 --access-logfile - --workers 3 --bind unix:/home/demouser/myproject.sock home.wsgi.dev:application
    

    【讨论】:

      猜你喜欢
      • 2015-10-01
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 2020-01-10
      • 2019-05-22
      • 2012-08-17
      相关资源
      最近更新 更多