thanks in advance. I have a Django app using Django-tenants. The app runs well locally but I haven’t been able to solve the subdomain for tenants. So far:
*.mydomain.com
, ip
, *.www.mydomain.com
, now I’m testing with ‘.*
’, ‘*
’code/conf
.server {
listen 80;
server_name *.mydomain;
location / {
rewrite ^ http://mydomain;
}
}
server {
listen 443 ssl http2;
server_name *.mydomain.com;
ssl_certificate /etc/nginx/ssl/mydomain_com_chain.crt;
ssl_certificate_key /etc/nginx/ssl/mydomain.com.key;
# SSL/TLS security settings
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDxxxxxxxxxxxxxxxxxx';
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /staticfiles/ {
root /root/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Hope someone can help me out. Thanks!!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello there!
The setup for the Django-tenants library using subdomains can be a bit tricky indeed.
You mentioned that you have already tried various configurations which sounds correct, what is the exact error that you currently get when you visit a tenant’s subdomain?
Let’s look at the configuration of Nginx and the Django settings:
server_name
directive in the Nginx configuration file correctly captures all subdomains:The
server_name
should be set to*.mydomain.com
andmydomain.com
so that it can serve both the root domain and any subdomains.Django settings.py: For your
ALLOWED_HOSTS
in your settings.py file, try using['.mydomain.com', 'mydomain.com']
. The leading dot allows all subdomains.Django-tenants: Make sure you have correctly set up the Django-tenants middleware. In your settings.py, you should have something like:
Ensure that your
TENANT_MODEL
is correctly set too.domain_url
value.Lastly, consider checking your logs for any error messages. Django’s logs can be very helpful, and so can Nginx’s. You can view the Nginx error logs with
sudo tail -f /var/log/nginx/error.log
.UPDATE: The issue was related to DNS propagation and it was working fine on the next day!
Let me know how it goes!
Best,
Bobby
thanks for the quick response. Today is working 😃, so I guess it was just a slowed dns propagation problem (just my thoughts on this). Just in case some has problems with this library I had to migrate all apps in shared apps and then move te tenants ones to tenant, otherwise I kept having migration problems. Thanks Bob!