Insights from Our Experts
How to host your django project to production server
When you finish your django project the very next step is to deploy it to the production server. You might have already setup a development server to show you project to others(may be your customers).
Here I am not discussing about development but about deployment in production server - the final step to take your project live.
The Django supports many ways to deploy the project to production- you can use your favourite web server, database, proxy, and so on.
Example architecture of django production server
- Apache, nginx, lighttpd, cherokee
- mod_python, mode_wsgi, Gunicorn, uwsgi, FastCGI
- MySQL/ Postgres/ Other databases
- Celery, cron
- RabbitMQ, Redis
A Web server is a program that uses the client/server model and the World Wide Web's Hypertext Transfer Protocol ( HTTP ) to serve the files from Web pages to Web users (whose computers contain HTTP clients that forward their requests). There are many web servers available for us to choose from. We can use any of Apache, nginx or lighttpd. But when we choose a web server we need to select an appropriate submodule compatible to it from mod_python, mode_wsgi, Gunicorn, uwsgi, FastCGI. For example we can use apache with mod_python or mode_wsgi, nginx with uwsgi or gunicorn.
There are some tasks which will take a very long time finish and a user need not to wait for its result. In such cases, we can make the background task towork in different thread or may be in different server all together . We can make use of celery here.
- Celery - Celery is an asynchronous task/job queue based on distributed message passing .Celery is written in Python, but the protocol can be implemented in any language.
- Workers - Used to process the messages sent by Celery. we can set multiple workers.
- Supervisor - It is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. We can start/ stop Celery using this.
- Broker - We have to run some broker in some server to process our tasks. We can use RabitMQ or Redis for this
When our project is hosted, we need to monitor it using some tools to check its performance, its error logs and user interactions.We have some tools available for this.
Graphite - Graphite provides real-time visualization and storage of numeric time-series data on an enterprise level.
Statsd - A network daemon that runs on the Node.js platform and listens for statistics, like counters and timers, sent over UDP or TCP and sends aggregates to one or more pluggable backend services (e.g.,Graphite).
Sentry - logging - Sentry is a modern error logging and aggregation platform.
New Relic - A software analytics tool suite used by developers, ops, and software companies to understand how your applications are performing in development and production.
Our live project definitely needs continuous development and deployment. So, we definitely need some deployment automation tool that simplifies our deployment.
On of them is Fabric - Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
There are some deployment checklists which Django mentions in their docs.
https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/. You need to go through this before you host your project to production server.