meh*_*hdi 4 environment-variables django uwsgi 18.04
我正在使用 django,现在尝试使用 nginx 和 uwsi 配置服务器。现在我运行 nginx+socket+uwsgi_emperor 很好。为了运行 uwsgi 我在终端中使用以下命令:
/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
Run Code Online (Sandbox Code Playgroud)
而且效果很好。现在我想添加服务,systemctl {start|stop|restart|status} uwsgi.service以便我可以轻松使用 uwsgi。这里出现问题。这里是/etc/systemd/system/uwsgi.service:
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
# i'm putting code same code of terminal exactly here:
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
现在,当我开始systemctl start uwsgi.service运行它时,我可以看到systemctl status uwsgi.servicethaat 已加载良好,但是当我想访问 ip 时,会出现错误,显示journalctl -b -u uwsgi我的 django 无法访问(读取)环境变量。因为我在 django 中使用了多个环境变量如果没有它们的值,django 就无法正常工作。为什么会发生这种情况?(当我在命令行中运行 uwsgi 时一切都很好,但是当我想在 systemctl 中使用相同的命令时,django 无法读取环境变量并发生错误)。谢谢
显示我的 django 无法访问(读取)环境变量
因为 systemd 没有在您的用户、用户环境和这些变量的 shell 中运行。
当我在命令行中运行 uwsgi 时
那么您将在该环境和这些变量中使用您自己的用户。
你需要一个
EnvironmentFile=/dir/to/file
Run Code Online (Sandbox Code Playgroud)
在你的ExecStart. 或者如果不是那么多你也可以这样做
Environment={VAR}={VALUE}
Run Code Online (Sandbox Code Playgroud)
(每个变量一行)其中
| 归档时间: |
|
| 查看次数: |
9245 次 |
| 最近记录: |