1 project, X app = X subdomains (Django, Apache)

32 views
Skip to first unread message

Jakub Jiřička

unread,
May 23, 2019, 2:54:04 PM5/23/19
to Django users
Hi,

I want to ask you if someone has solved how to prove that is possible the applications in one project run in different subdomains?

I have 1 project (projekt.cz) and provide of 3 applications (app1, app2, app3) and I would like to get on my vps (CentOS, Apache, PostgreSQL, Django) app1.projekt.cz app2.projekt.cz and app3.projekt.cz

I searched everywhere and I found only django-subdomains and django-domains ... unfortunately, I have not managed to get started, because out-of-date ...

So, there is someone who can help me with settings Django for this task/problem?

Many thanks and regards
Jakub

Tim Chase

unread,
May 23, 2019, 5:39:53 PM5/23/19
to django...@googlegroups.com
On 2019-05-23 06:22, Jakub Jiřička wrote:
> I want to ask you if someone has solved how to prove that is
> possible the applications in one project run in different
> subdomains?
>
> I have 1 project (projekt.cz) and provide of 3 applications (app1,
> app2, app3) and I would like to get on my vps (CentOS, Apache,
> PostgreSQL, Django) app1.projekt.cz app2.projekt.cz and
> app3.projekt.cz

I can read two interpretations of what what you describe:

1) each application is distinct/independent and you want each one to
run on its own subdomain. This seems like the most sensible
interpretation and is fairly straightforward: you configure your
web server (apache, from your description) to farm out different
subdomains:

<VirtualHost *:80>
ServerName app1.example.com
DocumentRoot /var/www/vhosts/app1
WSGIScriptAlias / /var/www/vhosts/app1/myproject1/wsgi.py

</VirtualHost>
<VirtualHost *:80>
ServerName app2.example.com
DocumentRoot /var/www/vhosts/app2
WSGIScriptAlias / /var/www/vhosts/app2/myproject2/wsgi.py

</VirtualHost>

with the relevant configuration in each block.


2) if you want to run the same Django code, backing multiple
subdomains with the same codebase, you want a wildcard subdomain
pointed at

<VirtualHost *:80>
ServerAlias *.example.com

</VirtualHost>

and then sniff the Host: HTTP header which something like
django-subdomains helps to make easier.

> I searched everywhere and I found only django-subdomains and
> django-domains ... unfortunately, I have not managed to get
> started, because out-of-date

I'm not sure what you mean by "because out-of-date". While
they both appear to have been last updated in 2016, I imagine they
got to the point where they just worked and didn't need much more
care & feeding. I'd assume they're fine unless you hit an issue with
them.

-tkc











Aldian Fazrihady

unread,
May 23, 2019, 6:08:23 PM5/23/19
to django...@googlegroups.com
Official way:
1. Run separate wsgi process for each subdomain. Each wsgi process uses unique Unix or TCP socket. 
2. Each wsgi process uses its own Django settings that points to the specific app's urls.py
3. The web server configuration for each subdomain points to the socket of the Django app representing that subdomain. 

Unofficial way:
Create path rewriting rule in wsgi configuration. 

I have used those both ways in the past. If your machine has very limited RAM,  such as 1 GB or below that,  I suggest you to try the second way. 


Regards, 

Aldian Fazrihady

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d2ddb92-5aec-4155-9071-d8c3a69ebee6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages