server {
    listen {{ DISCERN_NGINX_PORT }};
    server_name localhost;

    set $my_host $http_host;
    if ($host ~ "\d+\.\d+\.\d+\.\d+") {
        set $my_host "127.0.0.1";
    }

    # https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
    location /static/ { # STATIC_URL
        alias {{ discern_app_dir }}/staticfiles/;
        expires 1m;
	autoindex on;
    }

    location /media/ { # MEDIA_URL
        alias /home/www/myhostname/static/; # MEDIA_ROOT
        expires 30d;
    }

    location / {
        {% include "basic-auth.j2" %}
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
        proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
        proxy_set_header Host $my_host;

        proxy_pass http://127.0.0.1:7999;
    }
}

