jazzband / django-hosts

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.
http://django-hosts.rtfd.org
Other
982 stars 106 forks source link

Problems with subdomains served by nginx #146

Closed ctrlmaniac closed 2 years ago

ctrlmaniac commented 2 years ago

I have problem with static and media sites which are served by two different subdomains with nginx. However I can't reach them because django always displays the default host!

settings.py

ROOT_HOSTCONF = "webapp.hosts"
DEFAULT_HOST = "www"
ROOT_URLCONF = "www.urls"

hosts.py

from django.conf import settings
from django_hosts import host, patterns

host_patterns = patterns(
    "",
    host(r"www", settings.ROOT_URLCONF, name="www"),
    host(r"api", "api.urls", name="api"),
    host(r"admin", "webapp.urls", name="admin"),
)

Is it possible to ignore media and static subdomain?

ddabble commented 2 years ago

This sounds like an issue with your Nginx configuration (assuming that Nginx passes requests to your Django server). I happen to know (some of) the basics of configuring an Nginx server, so if you want, it could be helpful if you posted the config code here 🙂 Do you have separate server blocks for the Django server and the media and static subdomains, and do the server block(s) for those subdomains have server_names that do not overlap with the one of the server block for your Django server?

ctrlmaniac commented 2 years ago

I resolved by serving static and media files with the main domain