我为我的网站使用nginx + gunicorn + django。
以下是我的gunicorn.conf文件:
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 \
当我跑步
service gunicorn start
当我更改为dir /home/django ,以下命令(与前一个configuration文件中的代码相同)的工作方式类似于一个魅力:
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
但是第一个不能启动,当我删除configuration文件中的日志logging部分:exec gunicorn \ – name = eduwiki \ –pythonpath = eduwiki \ –bind = 0.0.0.0:9000 \ –config / etc / gunicorn.d / gunicorn.py \ eduwiki.wsgi:应用程序随着service gunicorn start ,服务运行。 但是它和terminal直接运行有所不同。
当从terminal直接运行时,网页中显示的字符编码是正确的,如下所示:
math(来自希腊文,“知识,学习,学习”)
但是当我使用服务运行gunicorn时,非ascii字符的编码是完全错误的:
*
math(来自希腊语,马克思,知识,学习,学习?)
您的交互式terminal会话通常会自动填充区域设置LC_ALL和语言设置LC_LANG和LANG而许多SSH客户端将通过从工作站转发这些环境variables来覆盖服务器默认设置。
通常这些与系统默认设置不同,当守护程序作为启动脚本的服务启动时,系统默认设置会被使用。 取消注释启动脚本中的# export行,并使用适当的设置填充环境。