upstream $SERVICE {
  server unix:/var/run/djevops/$SERVICE.sock fail_timeout=0;
}

server {
    server_name $SERVER_NAME;

    listen 80;

    include /etc/nginx/includes/$SERVICE-ssl;

    access_log /var/log/$SERVICE-access.log;
    error_log /var/log/$SERVICE-error.log;

    client_max_body_size $CLIENT_MAX_BODY_SIZE;

    gzip on;
    # Let caches key on Accept-Encoding:
    gzip_vary on;
    # Also compress responses proxied from the Django app, not just static
    # files. Without this, nginx would not compress anything from Django:
    gzip_proxied any;
    # Don't bother compressing tiny responses. (Nginx's default 20 is too low.)
    gzip_min_length 256;
    gzip_comp_level 5;
    # text/html is always compressed, so it is not listed here:
    gzip_types application/json application/javascript text/css image/svg+xml
               text/plain application/xml;

    location /static/ {
        alias /srv/static/;
    }

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        $PROXY_SSL_HEADER
        proxy_set_header Host $host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://$SERVICE;
            break;
        }
    }
}
