Serving multiple subdomains with NGINX

We need NGINX to be able to serve our site with any possible subdomain. Edit the config/nginx.conf file and replace this line:

server_name  www.educaproject.com educaproject.com;

With the following one:

server_name  *.educaproject.com educaproject.com;

By using the asterisk, this rule applies to all subdomains of educaproject.com. In order to test our middleware locally, we need to add any subdomains we want to test to /etc/hosts. For testing the middleware with a Course object with the slug django, add the following line to your /etc/hosts file:

127.0.0.1  django.educaproject.com

Then open https://django.educaproject.com/ in your browser. The middleware will find the course by the subdomain and redirect ...

Get Django 2 by Example 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.