Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

apache - Can Django serve different domains inside one single project?

I looked into the "sites" framework of Django but it requires to split the setting.py files for each website and I'm not sure how to handle all of them via the wsgi processes in Apache properly, separated but still communicating with each other in the background, while granting the security of my sites (no spoofing problems to access other websites within the same project).

I'm also trying out all the request object attributes to determine what the host is like

request.get_host()

which gives me the URL but it looks pretty easy to spoof or also

request.site

of the CurrentSiteMiddleware. I'm also trying the get_current_site method like this

get_current_site(request)

and I even address the .domain attribue itself. However I never reliably seem to be recognizing the actual domain being called by the browser, like it always refers to the value SITE_ID attribute of my settings.py . It seems the sites framework is not so useful other than for "mere" model association.

I also tried to omit the SITE_ID attribute inside my settings.py in order to test the CurrentSiteMiddleware but the output of all those methods above didn't change at all.

I'm not using subdomains, they're completely different domains.

Can anybody please direct me to some proper and secure (not easily spoofable) procedures that I could deploy on a VPS to handle a few domains that will have a lot of content in common?

I only found this possible solution: https://www.fir3net.com/Web-Development/Django/how-to-serve-multiple-domains-from-within-a-single-django-project.html but it doesn't explain exactly how to replicate the WSGI directives inside Apache for each domain. By reading this guide http://www.tobiashinz.com/2019/04/10/apache-django-virtualenv.html it seems it is possible to add multiple WSGI directives inside the same apache2 site conf file. It doesn't involve multiple settings.py files though, unlike what the official Django docs say. This seems to be a good start, mostly Apache-based, however it creates a domain.tld/website_folders pattern which is not what I look for. I think this is the closest I got Multiple Domain Hosting With One Django Project and I need to do the same in Apache, hoping it is possible.

I looked into a few django modules such as django-hosts and django-multisite too, django-dynamicsites seems to have been abandoned too, but I'd rather use some more natural solutions to improve maintainability and possibly security

question from:https://stackoverflow.com/questions/65891106/can-django-serve-different-domains-inside-one-single-project

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...