title: Django ERROR: Invalid HTTP_HOST header: u'/run/myprojectname/gunicorn.sock:'
body: <p><em>I know that there are a lot of questions like this on SO, but none of them appear to answer my particular issue.</em></p>
  
  <p>I understand that Django's <code>ALLOWED_HOSTS</code> value is blocking any requests to port <code>80</code> at my IP that do not come with the appropriate <code>Host:</code> value, and that when a request comes in that doesn't have the right value, Django is dropping me an email.  I also know about the <a href="https://stackoverflow.com/a/17477436/231670">slick Nginx hack</a> to make this problem go away, but I'm trying to understand the nature of one such request and determine whether this is a security issue I need to worry about.</p>
  
  <p>Requests like these make sense:</p>
  
  <pre><code>[Django] ERROR: Invalid HTTP_HOST header: '203.0.113.1'.  You may need to add u'203.0.113.1' to ALLOWED_HOSTS.
  </code></pre>
  
  <p>But this one kind of freaks me out:</p>
  
  <pre><code>[Django] ERROR: Invalid HTTP_HOST header: u'/run/my_project_name/gunicorn.sock:'.
  </code></pre>
  
  <p>Doesn't this mean that the requestor sent <code>Host: /run/my_project_name/gunicorn.sock</code> to the server?  If so, how do they have the path name for my <code>.sock</code> file?  Is my server somehow leaking this information?</p>
  
  <p>Additionally, as I'm running Django 1.6.5, I don't understand why I'm receiving these emails at all, as <a href="https://code.djangoproject.com/ticket/19866" rel="noreferrer">this ticket</a> has been marked fixed for some time now.</p>
  
  <p>Can someone shed some light on what I'm missing?</p>
  
  <p>This is my <code>settings.LOGGING</code> variable:</p>
  
  <pre><code>{
      'disable_existing_loggers': False,
      'filters': {
          'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse'}
      },
      'formatters': {
          'simple': {'format': '%(levelname)s %(message)s'},
          'verbose': {'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'}
      },
      'handlers': {
          'console': {
              'class': 'logging.StreamHandler',
              'formatter': 'verbose',
              'level': 'DEBUG'
          },
          'mail_admins': {
              'class': 'django.utils.log.AdminEmailHandler',
              'filters': ['require_debug_false'],
              'level': 'ERROR'
          }
      },
      'loggers': {
          'django.request': {
              'handlers': ['mail_admins'],
              'level': 'ERROR',
              'propagate': True
          },
          'my_project_name': {
              'handlers': ['console'], 
              'level': 'DEBUG'
          }
      },
      'version': 1
  }
  </code></pre>
  
  <p>And here's my nginx config:</p>
  
  <pre><code>worker_processes 1;
  pid /run/nginx.pid;
  error_log /var/log/myprojectname/nginx.error.log debug;
  events {
  }
  http {
    include mime.types;
    default_type application/octet-stream;
    access_log /var/log/myprojectname/nginx.access.log combined;
    sendfile on;
    gzip on;
    gzip_http_version 1.0;
    gzip_proxied any;
    gzip_min_length 500;
    gzip_disable "MSIE [1-6]\.";
    gzip_types text/plain text/html text/xml text/css
               text/comma-separated-values
               text/javascript application/x-javascript
               application/atom+xml;
    upstream app_server {
      server unix:/run/myprojectname/gunicorn.sock fail_timeout=0;
    }
    server {
      listen 80 default;
      listen [::]:80 default;
      client_max_body_size 4G;
      server_name myprojectname.mydomain.tld;
      keepalive_timeout 5;
      root /var/www/myprojectname;
      location / {
        try_files $uri @proxy_to_app;
      }
      location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_pass http://app_server;
      }
      error_page 500 502 503 504 /500.html;
      location = /500.html {
        root /tmp;
      }
    }
  }
  </code></pre>
  
  <p>Lastly, I found this in my nginx access log.  It corresponds to the emails coming through that complain about /run/myprojectname/gunicorn.sock being an invalid HTTP_HOST header.*</p>
  
  <p>This was all on one line of course:</p>
  
  <pre><code>2014/09/05 20:38:56 [info] 12501#0: *513 epoll_wait() reported that client
  prematurely closed connection, so upstream connection is closed too while sending
  request to upstream, client: 54.84.192.68, server: myproject.mydomain.tld, request:
  "HEAD / HTTP/1.0", upstream: "http://unix:/run/myprojectname/gunicorn.sock:/"
  </code></pre>
  
  <p>Obviously I still don't know what this means though :-(</p>
  
  <ul>
  <li><strong><em>Update #1</strong>: Added my <code>settings.LOGGING</code></em></li>
  <li><strong><em>Update #2</strong>: Added my nginx config</em></li>
  <li><strong><em>Update #3</strong>: Added an interesting line from my nginx log</em></li>
  <li><strong><em>Update #4</strong>: Updated my nginx config</em></li>
  </ul>