django-nginx-gunicorn - 不工作

时间:2012-05-20 10:29:12

标签: python django nginx gunicorn

我正试图通过这些教程http://senko.net/en/django-nginx-gunicorn/http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn

来设置django与nginx和gunicorn

设定:

virtualenv --no-site-packages qlimp
cd qlimp
source bin/activate
pip install gunicorn django
django-admin.py startproject qlimp
cd qlimp
python manage.py runserver 0.0.0.0:8001

Gunicorn设置与此处http://senko.net/en/django-nginx-gunicorn/

相同

所做的更改(run.sh):

LOGFILE=/var/log/gunicorn/qlimp.log
USER=nirmal
GROUP=nirmal
cd /home/nirmal/qlimp/qlimp

Upstart也与上面的链接

中的教程相同

所做的更改:

exec /home/nirmal/qlimp/qlimp/run.sh

Nginx设置:

server {
    listen 80;
    server_name qlimp.com;

    access_log /home/nirmal/qlimp/log/access.log;
    error_log /home/nirmal/qlimp/log/error.log;

    location /static {
         root /home/nirmal/qlimp/qlimp;
    }

    location / {
        proxy_pass http://127.0.0.1:8888;
    }

}

然后我重新启动了nginx并运行了gunicorn服务器:

sudo /etc/init.d/nginx restart
(qlimp) cd qlimp/qlimp
(qlimp) gunicorn_django -D -c run.sh

当我运行gunicorn服务器时,我收到此错误:

Failed to read config file: run.sh
Traceback (most recent call last):
File "/home/nirmal/qlimp/local/lib/python2.7/site-packages/gunicorn/app/base.py", line  65, in load_config
execfile(opts.config, cfg, cfg)
 File "run.sh", line 3
   LOGFILE=/var/log/gunicorn/qlimp.log
        ^
SyntaxError: invalid syntax

有人可以指导我吗?谢谢!

2 个答案:

答案 0 :(得分:0)

尝试/etc/gunicorn.d而不是您自己的sh文件

答案 1 :(得分:0)

我在EC2上使用Gunicorn和Nginx配置Django App

nano /etc/init/site1.conf

description "site1 web server"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
exec /home/scripts/gunicorn_runserver.sh

并在gunicorn_runserver.sh

#!/bin/bash
  set -e
  LOGFILE=/var/log/nginx/site1.log
  NUM_WORKERS=10
  # user/group to run as
  USER=www-data
  GROUP=adm
  cd /home/projects/project_name/
  #  source ../../bin/activate
  exec gunicorn_django -w $NUM_WORKERS \
    --user=$USER --group=$GROUP --log-level=error \
    --log-file=$LOGFILE 2>>$LOGFILE

Nginx conf

upstream app_server_hana {
server localhost:8000 fail_timeout=0;
}

location  / {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;

  if (!-f $request_filename) {
          proxy_pass http://app_server_site1;
          break;
  }
}

最后

/etc/init.d/nginx restart
service site1 start