Answer the question
In order to leave comments, you need to log in
Setting up virtualhosts in uWSGI?
I want to try to make two sites with one backend.
I plan to use Django-sites-framework + uWSGI + NGINX . I found information on setting up the latter on the network, but I didn’t manage to find much on the Django-sites-framework + uWSGI bundle. As far as I understood from what I managed to read, you need to configure uWSGI sockets and virtualhosts to direct requests to the appropriate sites. Does anyone know how to configure using two domains as an example?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Hey!
On the example of my task: one database for several sites of the same type, it was necessary to display a different main page, load slightly different css styles, contacts, etc.
In settings.py
INSTALLED_APPS = [
...
'django.contrib.sites',
...
]
ALLOWED_HOSTS = ['subdomen.example.com', 'example.com', 'subdomen2.example.com']
current_site = get_current_site(request).domain # можно использовать id, но мне показалось нагляднее использовать domain
if current_site == 'subdomen.example.com':
# ...some logic например разный context или template
elif current_site == 'subdomen2.example.com':
# ...some logic например разный context или template
...
location / {
# в сокет
proxy_pass http://unix:/tmp/example.socket;
# в порт, выбери одно
#proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question