
server {
    listen 80;
    client_max_body_size 4G;
    server_name {{ domain_name }};
    keepalive_timeout 5;

    gzip on;
    gzip_comp_level 7;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;

    access_log {{ cwd }}/logs/access.log timed_combined;
    error_log {{ cwd }}/logs/error.log;

    location /static/ {
            alias {{ static_root }}/;
            gzip on;
            gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
            gzip_comp_level 9;
            expires 1w;
            try_files $uri $uri/ =404;
    }

    location /uploads/ {
            alias {{ uploads_folder }}/;
            gzip on;
            gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
            gzip_comp_level 9;
            expires 1w;
            try_files $uri $uri/ =404;
    }

    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;

            proxy_pass http://127.0.0.1:{{ proxy_port }};
    }
    {% if use_pagespeed %}
    pagespeed on;
    pagespeed EnableFilters collapse_whitespace,insert_dns_prefetch,rewrite_images,combine_css,combine_javascript,flatten_css_imports,inline_css,rewrite_css,;
    # Needs to exist and be writable by nginx.
    pagespeed FileCachePath /var/nginx_pagespeed_cache;

    # Ensure requests for pagespeed optimized resources go to the pagespeed handler
    # and no extraneous headers get set.
    location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        add_header "" "";
    }
    location ~ "^/ngx_pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon$" { }
    location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
    location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
    location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
    {% endif %}
}