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!
Accepted Answer
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:server {
listen 443 ssl http2;
server_name *.mydomain.com mydomain.com;
# ...
}
The server_name
should be set to *.mydomain.com
and mydomain.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:
MIDDLEWARE = [
...
'django_tenants.middleware.main.TenantMainMiddleware',
...
]
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!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.