title: django errno 104 Connection reset by peer
body: <p>I am trying to run my django server on an Ubuntu instance on AWS EC2. I am using gunicorn to run the server like this :</p>
  
  <p><code>gunicorn --workers 4 --bind 127.0.0.1:8000 woc.wsgi:application --name woc-server --log-level=info --worker-class=tornado --timeout=90 --graceful-timeout=10</code></p>
  
  <p>When I make a request I am getting 502, Bad Gateway on the browser. Here is the server log <a href="http://pastebin.com/Ej5KWrWs" rel="noreferrer">http://pastebin.com/Ej5KWrWs</a></p>
  
  <p>Some sections of the settings.py file where behaviour is changed based on hostname are</p>
  
  <p>iUbuntu is the hostname of my laptop</p>
  
  <pre><code>if socket.gethostname() == 'iUbuntu':
      '''
      Development mode
      "iUbuntu" is the hostname of Ishan's PC
      '''
      DEBUG = TEMPLATE_DEBUG = True
  else:
      '''
      Production mode
      Anywhere else than Ishan's PC is considered as production
      '''
      DEBUG = TEMPLATE_DEBUG = False
  
  if socket.gethostname() == 'iUbuntu':
      '''Development'''
      ALLOWED_HOSTS = ['*', ]
  else:
      '''Production Won't let anyone pretend as us'''
      ALLOWED_HOSTS = ['domain.com', 'www.domain.com',
                       'api.domain.com', 'analytics.domain.com',
                       'ops.domain.com', 'localhost', '127.0.0.1']
  </code></pre>
  
  <p>(I don't get what's the purpose of this section of the code. Since I inherited the code from someone and the server was working I didn't bothered removing it without understanding what it does)</p>
  
  <pre><code>if socket.gethostname() == 'iUbuntu':
      MAIN_SERVER = 'http://localhost'
  else:
      MAIN_SERVER = 'http://domain.com'
  </code></pre>
  
  <p>I can't figure out what's the problem here. The same code runs fine with gunicorn on my laptop.</p>
  
  <p>I have also made a small hello world node.js to serve on the port 8000 to test nginx configuration and it is running fine. So no nginx errors.</p>
  
  <p>UPDATE:</p>
  
  <p>I set DEBUG to True and copied the Traceback <a href="http://pastebin.com/ggFuCmYW" rel="noreferrer">http://pastebin.com/ggFuCmYW</a></p>
  
  <p>UPDATE:</p>
  
  <p>Thanks to the reply by @ARJMP. This indeed is the problem with celery consumer not getting connected to broker.</p>
  
  <p>I am configuring celery like this : <code>app.config_from_object('woc.celeryconfig')</code> and the contents of celeryconfig.py are:</p>
  
  <p><code>BROKER_URL = 'amqp://celeryuser:celerypassword@localhost:5672/MyVHost'
  CELERY_RESULT_BACKEND = 'rpc://'</code></p>
  
  <p>I am running the worker like this :<code>celery worker -A woc.async -l info --autoreload --include=woc.async -n woc_celery.%h</code></p>
  
  <p>And the error that I am getting is:</p>
  
  <p><code>consumer: Cannot connect to amqp://celeryuser:**@127.0.0.1:5672/MyVHost: [Errno 104] Connection reset by peer.</code></p>