I am using nginx+gunicorn+django for my website.
The following is my gunicorn.conf file:
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectadly trigger a respawn
respawn
setuid django
setgid django
chdir /home/django
# export LC_ALL=en_US.UTF-8
# export LC_LANG=en_US.UTF-8
# export LANG=en_US.UTF-8
exec gunicorn \
--name=eduwiki \
--pythonpath=eduwiki \
--bind=0.0.0.0:9000 \
--log-level debug \
--log-file /var/log/gunicorn/error_logs.log \
--config /etc/gunicorn.d/gunicorn.py \
eduwiki.wsgi:application
# --access-logfile /var/log/gunicorn/acclogs.log \
When I run
service gunicorn start
And when I change to the dir /home/django
, the following command (which is the same as the codes in the former config file) worked like a charm:
exec gunicorn --name=eduwiki --pythonpath=eduwiki --bind=0.0.0.0:9000 --log-level debug --log-file /var/log/gunicorn/error_logs.log --config /etc/gunicorn.d/gunicorn.py eduwiki.wsgi:application
But the first one cannot be started, when I remove the logging part in the config file:
exec gunicorn \
–name=eduwiki \
–pythonpath=eduwiki \
–bind=0.0.0.0:9000 \
–config /etc/gunicorn.d/gunicorn.py \
eduwiki.wsgi:application
Withservice gunicorn start
, the service runs. But it behaves differently from directly running in terminal.
When running directly from terminal, the character encoding showing in the webpage is correct, like the following:
Mathematics (from Greek μάθημα máthēma, “knowledge, study, learning”)
But when I run gunicorn using service, the encoding of non-ascii character is totally wrong:
*
Mathematics (from Greek ?????? m?th?ma, ?knowledge, study, learning?)
-
*
Best Answer
Your interactive terminal sessions is typically automatically populated with locale
LC_ALL
and language settingsLC_LANG
andLANG
and many SSH clients will override the server defaults by forwarding those environment variables from your workstation.Often those are different from the system defaults, which get used when a daemon starts as a service from the start-up scripts. Uncomment the
# export
lines in the start-up script and populate the environment with suitable settings.