#INFO=name=Prestashop
# Redirect 404 errors to prestashop
error_page 404 ${template_location}index.php?controller=404;

# Cloudflare / Max CDN fix
location ~* \.(eot|otf|ttf|woff(?:2)?)$ {
    add_header Access-Control-Allow-Origin *;
}

# Force pdf files to be downloaded
location ~* \.pdf$ {
    add_header Content-Disposition Attachment;
    add_header X-Content-Type-Options nosniff;
}

# Force files inupload directory to be downloaded
location /upload/ {
    add_header Content-Disposition Attachment;
    add_header X-Content-Type-Options nosniff;
}

# Images
rewrite /([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$1$2$3.jpg last;
rewrite /([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$1$2$3$4.jpg last;
rewrite /([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
rewrite /([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
rewrite /([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
rewrite /([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
rewrite /([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite /([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ ${template_location}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
rewrite /c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ ${template_location}img/c/$1$2$3.jpg last;
rewrite /c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ ${template_location}img/c/$1$2.jpg last;

# Source code directories
location ~ /(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
    deny all;
}
# vendor in modules directory
location ~ /modules/.*/vendor/ {
    deny all;
}
# Prevent exposing other sensitive files
location ~ \.(yml|log|tpl|twig|sass)$ {
    deny all;
}
# Prevent injection of php files
location ~ /upload {
    location ~ \.php$ {
        deny all;
    }
}
location ~ /img {
    location ~ \.php$ {
        deny all;
    }
}
try_files $uri $uri/ ${template_location}index.php?$uri&$args;
