title: Unable to run background tasks with Celery + Django + Gunicorn
body: <p>Stack:</p>
  
  <pre><code>Python v2.7
  Django v1.11
  Celery v4.3.0
  Gunicorn v19.7.1
  Nginx v1.10
  </code></pre>
  
  <blockquote>
    <p>When I try to run django server and celery <strong>manually</strong> the async tasks executes as expected. </p>
    
    <hr>
    
    <p>The problem comes when I am deploying <code>django</code> project using <code>Gunicorn</code> plus <code>Nginx</code>. 
    I tried running <code>Celery</code> using <code>supervisor</code> but it didn't help. </p>
  </blockquote>
  
  <hr>
  
  <p><code>views.py</code></p>
  
  <pre><code>def _functionA():
      _functionB.delay() #where _functionB is registered async task.
  </code></pre>
  
  <hr>
  
  <p><code>settings.py</code></p>
  
  <pre><code># Celery settings
  CELERY_BROKER_URL = 'redis://localhost:6379'
  CELERY_RESULT_BACKEND = 'redis://localhost:6379'
  CELERY_ACCEPT_CONTENT = ['application/json']
  CELERY_RESULT_SERIALIZER = 'json'
  CELERY_TASK_SERIALIZER = 'json'
  </code></pre>
  
  <hr>
  
  <p><code>celery_init.py</code></p>
  
  <pre><code>from __future__ import absolute_import
  import os
  
  from celery import Celery
  
  
  # set the default Django settings module for the 'celery' program.
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpi_server.settings')
  
  app = Celery('myproject')
  
  # Using a string here means the worker doesn't have to serialize
  # the configuration object to child processes.
  # - namespace='CELERY' means all celery-related configuration keys
  #   should have a `CELERY_` prefix.
  app.config_from_object('django.conf:settings', namespace='CELERY')
  
  # Load task modules from all registered Django app configs.
  app.autodiscover_tasks()
  </code></pre>
  
  <hr>
  
  <p><code>__init__.py</code></p>
  
  <pre><code>
  
  # This will make sure the app is always imported when
  # Django starts so that shared_task will use this app.
  from myproject.celery_init import app as celery_app
  
  __all__ = ['celery_app']
  </code></pre>
  
  <p><code>gunicorn.service</code></p>
  
  <pre><code>[Unit]
  Description=Gunicorn application server....
  After=network.target
  
  [Service]
  User=root
  Group=www-data
  WorkingDirectory=&lt;myprojectdir&gt;
  Environment=PYTHONPATH=&lt;ENV&gt;
  ExecStart=&lt;myprojectdir&gt;/env/bin/gunicorn --workers 3 --access-logfile access_gunicorn.log --error-logfile error_gunicorn.log --capture-output --log-level debug --bind unix:&lt;myprojectdir&gt;/myproject.sock &lt;myproject&gt;.wsgi:application
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <hr>
  
  <p><code>myproject_nginx.conf</code></p>
  
  <pre><code>server {
      listen 8001;
      location / {
          include proxy_params;
          proxy_pass http://unix:&lt;myprojectdir&gt;/myproject.sock;
      }
  }
  </code></pre>
  
  <hr>
  
  <p><code>celery worker</code></p>
  
  <pre><code>celery worker -B -l info -A myproject -Q celery,queue1,queue2,queue3 -n beat.%h -c 1
  </code></pre>
  
  <hr>
  
  <p>Can anyone help me with my question(s) below:</p>
  
  <blockquote>
    <p>Why is that when Django is deployed using Gunicorn and nginx the Celery worker doesn't executes tasks whereas  when ran manually it is able to execute the tasks i.e. when ran with <code>python manage.py runserver ...</code> . </p>
  </blockquote>