【问题标题】:Starting uWSGI instance fails with code 203启动 uWSGI 实例失败,代码为 203
【发布时间】:2018-02-25 16:26:20
【问题描述】:

我想使用 nginx 和 uWSGI 在 Ubunut 16.04 上部署我的 Flask 应用程序,但是每当我执行 sudo systemctl start nebulon 时,我都没有收到错误,但状态显示如下:

nebulon.service - uWSGI instance to serve nebulon
   Loaded: loaded (/etc/systemd/system/nebulon.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2017-09-16 18:08:35 UTC; 5s ago
  Process: 18718 ExecStart=/nebulonapp/nebulon.sock --ini /nebulonapp/nebulon.ini (code=exited, status=203/EXEC)
 Main PID: 18718 (code=exited, status=203/EXEC)

nebulon.service:

[Unit]
Description=uWSGI instance to serve nebulon
After=network.target

[Service]
User=nebulonuser
Group=www-data
WorkingDirectory=/nebulonapp
ExecStart=/nebulonapp/nebulon.sock --ini /nebulonapp/nebulon.ini

[Install]
WantedBy=multi-user.target

/nebulonapp 我有nebulon.ini:

[uwsgi]
chdir=/nebulonapp/
wsgi-file = wsgi.py
callable = app
plugin=python35

master = true
processes = 5

socket = nebulon.sock
chmod-socket = 666
vacuum = true

die-on-term = true

nebulon.sock/nebulonapp 中,但它是空的。 uWSGI的状态如下:

uwsgi.service - LSB: Start/stop uWSGI server instance(s)
   Loaded: loaded (/etc/init.d/uwsgi; bad; vendor preset: enabled)
   Active: active (exited) since Sat 2017-09-16 18:22:53 UTC; 10s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18828 ExecStop=/etc/init.d/uwsgi stop (code=exited, status=0/SUCCESS)
  Process: 18854 ExecStart=/etc/init.d/uwsgi start (code=exited, status=0/SUCCESS)

Sep 16 18:22:53 nebulon systemd[1]: Stopped LSB: Start/stop uWSGI server instance(s).
Sep 16 18:22:53 nebulon systemd[1]: Starting LSB: Start/stop uWSGI server instance(s)...
Sep 16 18:22:53 nebulon uwsgi[18854]:  * Starting app server(s) uwsgi
Sep 16 18:22:53 nebulon uwsgi[18854]:    ...done.
Sep 16 18:22:53 nebulon systemd[1]: Started LSB: Start/stop uWSGI server instance(s).

使用以下命令测试 uWSGI 是可行的。

uwsgi --socket 0.0.0.0:5000 --plugin-python3 --protocol=http -w wsgi:app

感谢您的帮助。

【问题讨论】:

  • 你为什么要使用ExecStart=/nebulonapp/nebulon.sock --ini /nebulonapp/nebulon.ini 你从哪里得到的?您需要在服务而不是套接字中启动可执行文件
  • 谢谢。我是从 Stackoverflow 上的另一个问题中得到的。我正在遵循的教程说要像这样执行 ExecStart=/home/sammy/myproject/myprojectenv/bin/uwsgi --ini myproject.ini。但是这样做会给我同样的错误。
  • 如果我理解正确,您想将此uwsgi --socket 0.0.0.0:5000 --plugin-python3 --protocol=http -w wsgi:app 作为服务运行吗?如果是这样,请将您的服务更改为 ExecStart,然后在启动后显示服务的状态。你是否也在使用 virtualenv?
  • 谢谢。不幸的是,这也没有奏效。但是我切换到 mod_wsgi 和 Apache,现在它工作得很好。

标签: python ubuntu nginx flask uwsgi


【解决方案1】:

问题在于权限。您从数字海洋遵循的指南缺少关键步骤 - nginx 使用 www-data 组创建套接字,因此您需要将项目文件夹的所有权授予该组并确保您正在执行的用户with 是其中的一部分。

只需运行这两个命令

chown -R sammy:www-data /home/sammy/<project>/*

usermod -aG www-data sammy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 2014-08-28
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多