server {
    listen 80;
    server_name *.bl.test;
    root /var/www/bl.test;

    auth_basic "Test server";
    auth_basic_user_file /etc/nginx/bl.test.passwd;

    # Prevent access to pyc and py files.
    location ~ .*\.pyc? {
        return 404;
    }

    location ~ .git {
       return 404;
    }

    location ~ ^/.env$ {
        return 404;
    }

    location / {
        try_files /$host/$uri @gunicorn;
    }

    # Relay everything else to the django web server.
    location @gunicorn {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
        proxy_pass http://unix:/var/run/gunicorn/$host.sock;
    }
}