title: Django Nginx subdomain admin redirect error
body: <p>I have Django 1.4 configured with Nginx proxy and a remote authentication backend.</p>
  
  <p>The proxy is configured to server the django app as a subdomain and the authentication server as a subdomain so we have:</p>
  
  <pre><code>djangoapp.domain.com
  auth.domain.com
  </code></pre>
  
  <p>When visting the djangoapp for the first time it redirects to the auth domain to authenticate then returns back to the djangoapp domain.  This part works fine with the nginx proxy headers set for the subdomain</p>
  
  <pre><code>server {
      listen 443;
      ssl on;
      server name djangoapp.domain.com;
  
      location / {
         proxy_pass http://djangoapp
         proxy_set_header Host $host;
      }
  }
  </code></pre>
  
  <p>With the proxy_set_header Host $host; set authentication works, removing it breaks the authentication.  I had see other solutions suggesting this as a work around to fix django but this wont work in this case.</p>
  
  <p>The issue is mainly around the admin interface.  If you try to visit the admin site django tries to redirect to an invalid url. for example manually entering the url:</p>
  
  <pre><code>https://djangoapp.domain.com/admin
  </code></pre>
  
  <p>Redirects to</p>
  
  <pre><code>https://djangoapp.domain.com/.domain.com/admin
  </code></pre>
  
  <p>I am trying to understand why django is trying to redirect the partial url and not using the relative url?</p>
  
  <p>I have tried disabling the common middleware in django which stops the strange redirection, however by disabling this the django admin no longer automatically authenticates.</p>