title: How to add canonical header and 301 redirect in nginx
body: <p>I'm trying to add a canonical header in nginx on a location that is already returning a 301. I'm adding a canonical to the destination URL as the canonical link is more important to users than the actual URL showing in Google. I can't see the canonical response header coming through when checking dev tools?</p>
  
  <p>Current nginx routing is set up as</p>
  
  <pre><code>location ~* '^/folder/another-folder/important-document.pdf' {
    return 301 $scheme://$host/docs/destination-url;
  }
  </code></pre>
  
  <p>and I've tried adding the canonical URL as follows:</p>
  
  <pre><code>location ~* '^/folder/another-folder/important-document.pdf' {
    return 301 $scheme://$host/docs/destination-url;
    add_header Link "&lt;$scheme://$http_host/folder/another-folder/url&gt;; rel=\"canonical\"";
  }
  </code></pre>
  
  <p>The second example has been in prod for around 2 weeks and I'm still seeing the .PDF showing in Google organic results and no response headers in dev tools.</p>