I struggled with this problem for two days without success. I created an instance of the default Django application (1.6.1) called "testdj", installed it on an Amazon AWS EC2 t1.micro instance with Ubuntu Server 13.10 running, and I am trying to achieve standard Django. "He works!" through Gunicorn (v. 18). When I start firing from the command line:
gunicorn testdj.wsgi:application --bind [ec2-public-dns]:8001
I can see the page when I enter this url:
http:
However, if I use the "start-gunicorn" bash script that I created after reading the Karzynski blogpost "Configuring Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL", I always get an error. When I enter this URL ...
http:
... I get this error:
Error 502 - Bad Request
The server could not resolve your request for uri: http:
Here is the gun launcher script:
#!/bin/bash
NAME="testdj"
DJANGODIR=/usr/share/nginx/html/testdj
SOCKFILE=/usr/share/nginx/html/testdj/run/gunicorn.sock
USER=testdj
GROUP=testdj
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=testdj.settings
DJANGO_WSGI_MODULE=testdj.wsgi
WORKON_HOME=/home/testdj/venv
source `which virtualenvwrapper.sh`
workon $NAME
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGO_DIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--access-logfile /tmp/gunicorn-access.log \
--error-logfile /tmp/gunicorn-error.log \
--log-level=debug \
--bind=unix:$SOCKFILE
, "testdj" . Django . Django wsgi.py. nginx , nginx Django nginx/usr/share/nginx/html. / www-data /usr/share/nginx , , / "testdj" /usr/share/nginx/html/testdj . /usr/share/nginx/html/testdj, perms 775, www- testdj.
nginx, nginx. nginx, , .
upstream testdj_app_server {
server unix:/usr/share/nginx/html/testdj/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name ec2-[my-public-dns-ip].us-west-2.compute.amazonaws.com;
client_max_body_size 4G;
access_log /var/log/nginx/testdj-access.log;
error_log /var/log/nginx/testdj-error.log;
location /static/ {
alias /usr/share/nginx/html/testdj/static/;
}
location /media/ {
alias /usr/share/nginx/html/testdj/media/;
}
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://testdj_app_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /usr/share/nginx/html/testdj/static/;
}
}
, , , , "-bind = unix: $SOCKFILE" script "--bind - [ec2-public-dns]: 8000", Django. , DNS- 8000, 80 nginx -.
AWS, HTTP 80, 8000 8001 , , 502 .
, , , - . Django , :
2014-02-03 18:41:01 [19023] [INFO] Starting gunicorn 18.0
2014-02-03 18:41:01 [19023] [DEBUG] Arbiter booted
2014-02-03 18:41:01 [19023] [INFO] Listening at: unix:/usr/share/nginx/html/testdj/run/gunicorn.sock (19023)
2014-02-03 18:41:01 [19023] [INFO] Using worker: sync
2014-02-03 18:41:01 [19068] [INFO] Booting worker with pid: 19068
2014-02-03 18:41:01 [19069] [INFO] Booting worker with pid: 19069
2014-02-03 18:41:01 [19070] [INFO] Booting worker with pid: 19070
- , ? , . , , , " ". , , . , , . !