Nginx static server download zip prompt 404

1.nginx sets up a static file server for placing files packaged by webpack. But the zip under the static directory static prompts 404 for each download, and other types of files like .json .md can be downloaded normally.

2.nginx static server is mainly configured as follows

server {
        listen 80;
        server_name  xxx.xx.com;

        location / {
            root   /home/www;
            index  index.html index.htm;
            if ($request_filename ~* ^.*?/.(zip|apk)$) {
                add_header Content-Disposition: "attachment;";
            }
        }
}

3.nginx log is as follows:

[05/Jun/2018:06:54:49 +0000] "GET /static/test/data.zip HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

4.

Mar.17,2021

you have two questions here:

  1. add_header instruction has an extra colon :
  2. there is no need to use if instruction, use location better

so

            if ($request_filename ~* ^.*?/.(zip|apk)$) {
                add_header Content-Disposition: 'attachmet;';
            }
Change

to

            location ~* \.(zip|apk)$ {
                add_header Content-Disposition 'attachmet;';
            }
Menu