map $sent_http_content_type $expires {
    "text/html"                 1h; # set this to your needs
    "text/html; charset=utf-8"  1h; # set this to your needs
    default                     32d; # set this to your needs
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    "" close;
}

proxy_cache_path  /etc/nginx/cache/DOMAIN levels=1:2 keys_zone=DOMAIN-nuxt-cache:25m max_size=1g inactive=60m use_temp_path=off;

map $http_referer $frame_options {
    "~webvisor.com" "ALLOW-FROM http://webvisor.com";
    "~ami.responsivedesign.is" "ALLOW-FROM http://ami.responsivedesign.is";
    default "SAMEORIGIN";
}

server {

    server_name DOMAIN;
    root /var/www/web/sites/PROJECT_FOLDER/dist;

    add_header X-Frame-Options  $frame_options;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    location / {
        expires $expires;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_redirect              off;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                         http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }

    access_log off;

        # deny running scripts inside writable directories
        location ~* \.(?:ico|gif|jpe?g|png|woff2?|eot|otf|ttf|svg|txt)$ {
        expires $expires;
        add_header Pragma public;
        add_header Cache-Control "public";

        try_files $uri $uri/ @proxy;
    }


    location ~* \.(?:js|css)$ {
        expires $expires;
        add_header Pragma public;
        add_header Cache-Control "public";

        try_files $uri $uri/ @proxy;
    }

    location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css|woff|woff2|svg|mp4)$ {
        expires max;
        access_log  off;
        log_not_found   off;
    }


    location @proxy {
        expires $expires;
        add_header Content-Security-Policy "default-src 'self' 'unsafe-inline';";
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
        # add_header X-Frame-Options  $frame_options;
        add_header X-Cache-Status $upstream_cache_status;

        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_ignore_headers        Cache-Control;
        proxy_http_version          1.1;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                  http://localhost:3000; # set the adress of the Node.js instance here
        proxy_cache                 DOMAIN-nuxt-cache;
        proxy_cache_bypass          $arg_nocache; # probably better to change this
        proxy_cache_valid           200 302  60m; # set this to your needs
        proxy_cache_valid           404      1m;  # set this to your needs
        proxy_cache_lock            on;
        proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
        proxy_cache_key             $uri$is_args$args;
    }
}