Gunicorn 服务环境文件格式?

tbo*_*nst 6 python django ubuntu environment-variables gunicorn

I'm deploying a Django project on an ubuntu machine using gunicorn and nginx, following this tutorial to do it.

I have a gunicorn service that looks like this, similar to the one in the tutorial:

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

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/project/mysite
EnvironmentFile=/home/ubuntu/.virtualenvs/projectenv/bin/postactivate
ExecStart=/home/ubuntu/.virtualenvs/projectenv/bin/gunicorn --access-logfile - --workers 10 --bind unix:/home/ubuntu/project/mysite.sock mysite.wsgi:application

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

Since, as I understand, the gunicorn service is run in a completely new environment instead of my project's virtual environment I need to find another way to pass it environment variables. I found this page which says I can add an EnvironmentFile to my service file, which I did above.

I directed the environment file to my virtualenv's postactivate script, which looks something like this:

#!/bin/bash
# This hook is sourced after this virtualenv is activated.

export DJANGO_DEBUG=False
...
Run Code Online (Sandbox Code Playgroud)

Which doesn't work, unsurprisingly.

What is the correct format for this EnvironmentFile to be in?

小智 4

你只需要传递类似的东西:

DJANGO_DEBUG=False
PYTHON_PATH=:bla
Run Code Online (Sandbox Code Playgroud)

文档在这里