Django + Celery Setup on Microsoft Azure

Syaiful Sabril
1 min readMay 28, 2021

Maybe this setup is simple, but I cannot find any straight forward tutorial to do it on the internet. So I will write down my own finds here.

Connect your Django Celery to a Redis Server:

  1. Go to your Azure App Service page and check on Configuration -> Application Settings menu.
  2. Click + New Application Setting and fill the name with CELERY_BROKER_URL and the value with your Redis Cache endpoint URL. Make sure this Redis Endpoint active and your App Service has access to it.
  3. Click Save

Now your Django Celery can use the Redis, it’s time to make Celery to run. Because Celery use different command line to run, we will need a startup file to make it run and tell the Azure to run that startup file.

  1. Create a startup file named startup.sh in your project’s root folder.
  2. Fill the startup file content with this

export LANG=C.UTF-8

gunicorn — bind=0.0.0.0 — timeout 600 config.wsgi & celery -A config worker -l INFO -B

gunicorn is the default command to run the web server on azure and we combine it with the celery command .

Commit your code and push it to your Azure App Service.

Go to Configuration -> General Settings. In the startup command field, fill it with: startup.sh and then save it.

This command will be executed when the app server restart and that’s all.

The source of this info is here:
https://docs.microsoft.com/en-us/azure/developer/python/tutorial-deploy-app-service-on-linux-04

--

--