1

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?)

    *
0

1 Answer 1

1

Your interactive terminal sessions is typically automatically populated with locale LC_ALL and language settings LC_LANG and LANG 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.

1
  • You are right. Instead of export LC_ALL=en_US.UTF-8, I should have used env LC_ALL="en_US.UTF-8" which follows the syntax of the system V script. That's the reason why export did not work and I commented it.
    – moonkey
    Jun 18, 2015 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .