Chapter 10. Getting to a Production-Ready Deployment
Our deployment is working fine but itâs not production-ready. Letâs try to get it there, using the tests to guide us.
In a way weâre applying the Red-Green-Refactor cycle to our server deployment. Our hacky deployment got us to Green, and now weâre going to Refactor, working incrementally (just as we would while coding), trying to move from working state to working state, and using the FTs to detect any regressions.
What We Need to Do
Whatâs wrong with our hacky deployment? A few things: first, we need to host our app on the ânormalâ port 80 so that people can access it using a regular URL.
Perhaps more importantly, we shouldnât use the Django dev server for production; itâs not designed for real-life workloads. Instead, weâll use the popular combination of the Nginx web server and the Gunicorn Python/WSGI server.
Several settings in settings.py are currently
unacceptable too. DEBUG=True
, is strongly recommended against for production,
and weâll want to fix ALLOWED_HOSTS
, and set a unique SECRET_KEY
too.
Finally, we donât want to have to SSH in to our server to actually start the site. Instead, weâll write a Systemd config file so that it starts up automatically whenever the server (re)boots.
Letâs go through and see if we can fix each of these things one by one.
Switching to Nginx
Installation
Weâll need a real web server, and all the cool kids are using Nginx these days, so we will too. Having ...
Get Test-Driven Development with Python, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.