K
K
Konstantin Khairov2017-10-16 14:19:42
Nginx
Konstantin Khairov, 2017-10-16 14:19:42

How to make video download in nginx?

Hello everyone, how to implement the return of the video for downloading if there is a pointer GET parameter in the link? For example, so that a direct link sitename.com/video/name.mp4 would show a video online, but if you specify ?download=video after name.mp4, then the server would give this video for downloading and add a title.
Found this example

location ~* /video/(.*)$ {
    add_header Content-disposition "attachment; filename=$1";
    root /var/www/site.com/video;
}

But I don't know how to add the ability to take into account the presence of a GET parameter in it.
Made it like this
location /video/Disk1/ {
  if ($request_filename ~ "^.*/(.*)?download=video$"){
    set $fname $1;
    add_header Content-Disposition 'attachment; filename="$fname"';
  }
}

But it still continued to download. What is the problem? How to implement something like this? Thanks in advance .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-10-16
@Kaylos

if ($arg_download = "video") {
  add_header Content-disposition "attachment"
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question