Jordan Jambazov
Jordan Jambazov

Reputation: 3620

How to deploy multiple Django sites with DRY configuration?

Currently I am deploying more than 30 websites which are operated by a single application, written in Django. The sites are combined into smaller groups. For example, there is a group Europe, which includes websites Germany, France, Switzerland, etc. Those groups are 7.

For deployment uwsgi (operating in Emperior mode), nginx (uwsgi passing to the group socket) and supervisord (for task workers) are used. Application is using a single database for all websites.

The structure of settings files in the project currently is as follows:

So far I thought that it would be enough to simply have 7 uwsgi and 7 nginx configuration files (for each group), until I realized some of the websites will also need custom Django settings, and separate DJANGO_SETTINGS_MODULE will have to be defined for each website (some of those websites have different languages lets say).

Things to keep in mind:

What was considered so far:

Upvotes: 1

Views: 426

Answers (1)

GwynBleidD
GwynBleidD

Reputation: 20569

If you're using emperor mode and your uWSGI configs differs only in socket and DJANGO_SETTINGS_MODULE, consider using one config file for all sites. You will start new site basically by creating symlink in uWSGI emperor directory and special variables inside that config will construct socket names and DJANGO_SETTINGS_MODULE variable based on symlink name.

If you're only worried about urlpatterns, language and other values that can be determined at request, you can use django-hosts instead of built-in sites module. That will also allow you to serve multiple sites on one workers pool. You can also create some middleware for that purpose.

Note that you can also use environment variables (which can be set in uWSGI config file) to set some of settings. Just use os.environ in your settings file to extract them.

And last, but not least - settings file can be set dynamically in wsgi.py file based on some other variables.

Upvotes: 1

Related Questions