I'm trying to setup django with nginx and gunicorn by these tutorials http://senko.net/en/django-nginx-gunicorn/ and http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn
Setup:
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 setup is same as here http://senko.net/en/django-nginx-gunicorn/
changes made (run.sh):
LOGFILE=/var/log/gunicorn/qlimp.log
USER=nirmal
GROUP=nirmal
cd /home/nirmal/qlimp/qlimp
Upstart is also the same as the tutorial in above link
changes made:
exec /home/nirmal/qlimp/qlimp/run.sh
Nginx setup:
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;
}
}
Then I restarted nginx and run the gunicorn server:
sudo /etc/init.d/nginx restart
(qlimp) cd qlimp/qlimp
(qlimp) gunicorn_django -D -c run.sh
When I run the gunicorn server, I'm getting this error:
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
Could anyone guide me? Thanks!
试试/etc/gunicorn.d而不是你自己的sh文件
I Configure Django App with Gunicorn and Nginx on EC2
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
and in 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;
}
}
Finally
/etc/init.d/nginx restart
service site1 start
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.