http - Django ERROR: Invalid HTTP_HOST header: u'/run/myprojectname/gunicorn.sock:' -


i know there lot of questions on so, none of them appear answer particular issue.

i understand django's allowed_hosts value blocking requests port 80 @ ip not come appropriate host: value, , when request comes in doesn't have right value, django dropping me email. know slick nginx hack make problem go away, i'm trying understand nature of 1 such request , determine whether security issue need worry about.

requests these make sense:

[django] error: invalid http_host header: '203.0.113.1'.  may need add u'203.0.113.1' allowed_hosts. 

but 1 kind of freaks me out:

[django] error: invalid http_host header: u'/run/my_project_name/gunicorn.sock:'. 

doesn't mean requestor sent host: /run/my_project_name/gunicorn.sock server? if so, how have path name .sock file? server somehow leaking information?

additionally, i'm running django 1.6.5, don't understand why i'm receiving these emails @ all, this ticket has been marked fixed time now.

can shed light on i'm missing?

this settings.logging variable:

{     '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 } 

and here's nginx config:

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;     }   } } 

lastly, found in nginx access log. corresponds emails coming through complain /run/myprojectname/gunicorn.sock being invalid http_host header.*

this on 1 line of course:

2014/09/05 20:38:56 [info] 12501#0: *513 epoll_wait() reported client prematurely closed connection, upstream connection closed while sending request upstream, client: 54.84.192.68, server: myproject.mydomain.tld, request: "head / http/1.0", upstream: "http://unix:/run/myprojectname/gunicorn.sock:/" 

obviously still don't know means though :-(

  • update #1: added settings.logging
  • update #2: added nginx config
  • update #3: added interesting line nginx log
  • update #4: updated nginx config

seems like

proxy_set_header host $http_host 

should changed to

proxy_set_header host $host 

and server_name should set appropriately address used access server. if want catch all, should use server_name www.domainname.com "" (doc here).

i'm not think you're seeing happens if client doesn't send host: header. since nginx receives no host: header, no host: header gets passed gunicorn. @ point, think gunicorn fills in host: socket path , tells django since that's connection used. using $host , setting server_name in nginx should ensure host: correctly passed gunicorn , fix problem.

as email, according commit in ticket linked, looks emails still being sent disallowed hosts. added doc suggested way disable emails being sent:

    'loggers': {         'django.security.disallowedhost': {         'handlers': ['null'],         'propagate': false,     }, 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -