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’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
DEBUG=True, is strongly recommended against for production,
and we’ll want to fix
ALLOWED_HOSTS, and set a unique
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.
We’ll need a real web server, and all the cool kids are using Nginx these days, so we will too. Having fought with Apache for many ...