title: nginx: location condition + secure_link
body: <p>I have a hard time figuring out the correct configuration.</p>
  
  <p>I have an URL - e.g.</p>
  
  <pre><code>http://example.com/[md5-checksum]/[num-value-1]/[num-value-2]/[file-name]
  http://example.com/ac64392dba67d618ea6a76843c006708/123/56789/test.jpg
  </code></pre>
  
  <p>I want to make sure that the md5-checksum matches <em>salt + num-value-2</em>. So the file name and num-value-1 should be ignored (only needed for the filename header) in order to build the md5 checksum.</p>
  
  <p>Following configuration does not result in what I want to achieve.</p>
  
  <pre><code>location ~* ^/download/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)/(.*)$ {
  
     secure_link $3;
     secure_link_md5 segredo$3;
  
     if ($secure_link = "") {
        return 500;
     }
  
     set $filename $4;
     add_header Content-Disposition "attachment; filename=$filename";
     rewrite ^/download/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$2/$3 break;
  
  }
  </code></pre>
  
  <p>I appreciate any help!</p>