Deploy Django 1.7 Application (using DigitalOcean quick start tutorial) - Error 500 =(

September 28, 2014 4.6k views

Hello, everyone!

I tried to follow this tutorial link, but it hasn't worked for me. =(

I know that error 500 should be an application error, but, the application works fine on my computer.

This is nginx configs

upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name _;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/agenciafacilonline/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/agenciafacilonline/agenciafacilonline/static;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://104.131.104.172/;
    }
}

This is my gunicorn configs

description "Gunicorn daemon for Django project"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectedly trigger a respawn
respawn

setuid django
setgid django
chdir /home/django

exec gunicorn \
    --name=agenciafacilonline \
    --pythonpath=agenciafacilonline \
    --bind=0.0.0.0:9000 \
    --config /etc/gunicorn.d/gunicorn.py \
    django_project.wsgi:application

Do I need to do anything more?

Many thanks

@HigorSilvaRosa

1 comment
  • This is Nginx error log

    2014/09/27 18:43:18 [error] 929#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 187.2.131.147, server: _, request: "GET /admin HTTP/1.1", upstream: "http://127.0.0.1:9000/admin", host: "104.131.104.172"
    2014/09/27 18:43:18 [error] 929#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 187.2.131.147, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:9000/favicon.ico", host: "104.131.104.172"
    
    
2 Answers

I had a similar problem, and all logs were empty too !!

The problem with me was that I'm using environment variables in code, that was declared in .bashrc but wasn't read !
The solution was to declare those environment variable inside /etc/init/gunicorn.conf file.

env KEY=VALUE

And it works :)
This may help you, or if not check init files reference It may be more useful

The errors mean that whatever should be running on port 9000 isn't running, which is gunicorn in this case.

Check gunicorn's error log, are there any errors?

sudo tail -30 /var/log/upstart/gunicorn.log

Unrelated: I would replace --bind=0.0.0.0:9000 with --bind=127.0.0.1:9000 so that gunicorn itself can't be accessed externally (you want everything to go through nginx first).

Have another answer? Share your knowledge.