python – How can domain aliases be set up using Django? – Education Career Blog

I am working on creating a website in Django which consists of two parts: the website itself, and the forum. They will both be on separate domains, i.e. example.com and exampleforum.com. How can this be done in Django, when the forum and main site are part of the same instance?

,

This is done at the web server level. Django doesn’t care about the domain on the incoming request.

If you are using Apache just put multiple ServerAlias directives inside your virtual host like this:

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    ServerAlias forum.mydomain.com
    ... other directives as needed ...
</VirtualHost>

This tells Apache to direct requests for all of those domains into the same instance.

For nginx your config file would look something like:

server {
    listen 80;
    server_name   www.mydomain.com   mydomain.com   forum.mydomain.com;
    ... other directives as needed ...
}

Leave a Comment