External IP error on Django + Nginx + Gunicorn setup

Jesus Gomez

I've been getting a weird error on a production environment with Django + Gunicorn + Nginx, the application seems to be running fine but I'm getting this error at least dialy:

Invalid HTTP_HOST header: u'/home/ubuntu/my_apps/myapp/gunicorn.sock:'. The domain name provided is not valid according to RFC 1034/1035.

Request repr(): 
<WSGIRequest
path:/SiteMap.xml,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'HTTP_ACCEPT': '*/*',
 'HTTP_CONNECTION': 'close',
 'HTTP_USER_AGENT': 'masscan/1.0 (https://github.com/robertdavidgraham/masscan)',
 'HTTP_X_FORWARDED_FOR': '94.102.48.193',
 'PATH_INFO': u'/SiteMap.xml',
 'QUERY_STRING': '',
 'RAW_URI': '/SiteMap.xml',
 'REMOTE_ADDR': '',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': '/home/ubuntu/my_apps/myapp/gunicorn.sock',
 'SERVER_PORT': '',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'gunicorn/19.4.5',
 'gunicorn.socket': <socket._socketobject object at 0x7f86b919d4b0>,
 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f86b92d1650>,
 'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
 'wsgi.input': <gunicorn.http.body.Body object at 0x7f86b92d19d0>,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>

It does seem like these errors are triggered by external attack attempts but I'm clueless about why they'd be able to inject the exact location of the socket running my Django app in the HTTP HOST header. Any ideas about how this error can be avoided, is this exposing a likely vulnerability on my site?

EDIT:

This is my nginx config file:

upstream myapp {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  server unix:/home/ubuntu/my_apps/myapp/gunicorn.sock fail_timeout=0;
}

server {

    listen   80;
    server_name 0.0.0.0;

    client_max_body_size 4G;

    access_log /home/ubuntu/my_apps/myapp/logs/nginx-access.log;
    error_log /home/ubuntu/my_apps/myapp/logs/nginx-error.log;

    location /static/ {
        alias   /home/ubuntu/my_apps/myapp/myapp/static/;
    }

    location /media/ {
        alias   /home/ubuntu/my_apps/myapp/myapp/media/;
    }

    location /socket.io/ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://localhost:8888;
    }

    location / {
        # an HTTP header important enough to have its own Wikipedia entry:
        #   http://en.wikipedia.org/wiki/X-Forwarded-For
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # enable this if and only if you use HTTPS, this helps Rack
        # set the proper protocol for doing redirects:
        # proxy_set_header X-Forwarded-Proto https;

        # pass the Host: header from the client right along so redirects
        # can be set properly within the Rack application
        proxy_set_header Host $http_host;

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        # set "proxy_buffering off" *only* for Rainbows! when doing
        # Comet/long-poll stuff.  It's also safe to set if you're
        # using only serving fast clients with Unicorn + nginx.
        # Otherwise you _want_ nginx to buffer responses to slow
        # clients, really.
        # proxy_buffering off;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://myapp;
            break;
        }
    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/ubuntu/my_apps/myapp/myapp/static/;
    }
}
Maxime B

Wow, weird.

Edits to do in nginx.conf file (usually in /etc/nginx on Debian based systems)

You could just bypass this request attempt on this specific address by telling Nginx to drop it.

location ~ ^/home/ubuntu/my_apps/myapp/gunicorn.sock {
            deny all;
}

Or you can simply negates incoming connections from this suspicious User-Agent

if ($http_user_agent ~ (~*masscan)) {
 return 444;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

External IP error on Django + Nginx + Gunicorn setup

From Dev

nginx not working with gunicorn for external IP's

From Dev

nginx not working with gunicorn for external IP's

From Dev

Error Logging in Nginx+Gunicorn+Supervisor+Django

From Dev

URL resolution error using Gunicorn, Nginx, and Django

From Dev

restrict access to the admin url by ip in django with nginx and gunicorn

From Dev

Django, Gunicorn Setup

From Dev

nginx and gunicorn for a django project

From Dev

500 internal server error when deploy django with gunicorn and nginx

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

Django, nginx, gunicorn: why on some page gives Server Error (500)?

From Dev

Bad Request (400) and 502 error: Nginx, gunicorn, django

From Dev

How to setup a VPS with Django, Nginx, Gunicorn, Postgres and then properly deploy a Django application to it?

From Dev

Deploying Django project with Gunicorn and nginx

From Dev

Django Nginx Gunicorn = 504 Timeout

From Dev

Static files in Nginx, Gunicorn in Django

From Dev

Django Nginx Gunicorn = 504 Timeout

From Dev

Deploying Django project with Gunicorn and nginx

From Dev

nginx, gunicorn and django timing out

From Dev

Error Logging in Django and Gunicorn

From Dev

Django Gunicorn error

From Dev

Nginx, Flask, Gunicorn 502 Error

From Dev

Error handling request with gunicorn and nginx

From Dev

Django ERROR (EXTERNAL IP): Internal Server Error: /favicon.ico

From Dev

Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

From Dev

django nginx setup issues

From Dev

django nginx setup issues

From Dev

Invalid IP parameter on nginx setup

From Dev

'Invalid input syntax for type inet' db error in Django app with postgres and Gunicorn+Nginx as reverse proxy

Related Related

  1. 1

    External IP error on Django + Nginx + Gunicorn setup

  2. 2

    nginx not working with gunicorn for external IP's

  3. 3

    nginx not working with gunicorn for external IP's

  4. 4

    Error Logging in Nginx+Gunicorn+Supervisor+Django

  5. 5

    URL resolution error using Gunicorn, Nginx, and Django

  6. 6

    restrict access to the admin url by ip in django with nginx and gunicorn

  7. 7

    Django, Gunicorn Setup

  8. 8

    nginx and gunicorn for a django project

  9. 9

    500 internal server error when deploy django with gunicorn and nginx

  10. 10

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  11. 11

    Django, nginx, gunicorn: why on some page gives Server Error (500)?

  12. 12

    Bad Request (400) and 502 error: Nginx, gunicorn, django

  13. 13

    How to setup a VPS with Django, Nginx, Gunicorn, Postgres and then properly deploy a Django application to it?

  14. 14

    Deploying Django project with Gunicorn and nginx

  15. 15

    Django Nginx Gunicorn = 504 Timeout

  16. 16

    Static files in Nginx, Gunicorn in Django

  17. 17

    Django Nginx Gunicorn = 504 Timeout

  18. 18

    Deploying Django project with Gunicorn and nginx

  19. 19

    nginx, gunicorn and django timing out

  20. 20

    Error Logging in Django and Gunicorn

  21. 21

    Django Gunicorn error

  22. 22

    Nginx, Flask, Gunicorn 502 Error

  23. 23

    Error handling request with gunicorn and nginx

  24. 24

    Django ERROR (EXTERNAL IP): Internal Server Error: /favicon.ico

  25. 25

    Django+Gunicorn+nginx Internal Server Error, where is the error and how to fix it?

  26. 26

    django nginx setup issues

  27. 27

    django nginx setup issues

  28. 28

    Invalid IP parameter on nginx setup

  29. 29

    'Invalid input syntax for type inet' db error in Django app with postgres and Gunicorn+Nginx as reverse proxy

HotTag

Archive