2

How I can to serve the file:

'/webapps/app/static/downloads/privacy_policy.pdf'

by address:

https://my.site.net/privacy/

I try to use location in my nginx, but this not work:

location /privacy/ {
   alias /webapps/app/static/downloads/privacy_policy.pdf;
}
Stan Zeez
  • 1,138
  • 2
  • 16
  • 38

2 Answers2

12

I found solution. I move the pdf file in separate directory "privacy". I set the directory as alias and set I set pdf document as an index file:

location /privacy/ {
   alias /webapps/app/static/downloads/privacy/;
   index privacy_policy.pdf;
}
Stan Zeez
  • 1,138
  • 2
  • 16
  • 38
  • Hi, your solution works, but the file is downloaded without name :( – Ponzio Pilato May 26 '21 at 13:46
  • 1
    im getting a 403 forbidden using this solution – lopezdp Jun 08 '21 at 19:33
  • @lopezdp, make sure you have proper file/folder permissions to that location on your server for your nginx process user to read it – speed488 May 28 '22 at 14:51
  • 1
    @PonzioPilato If you want to specify the file name, you can use a `Content-Disposition` header (either `attachment` to download the file or `inline` to show its contents in the browser window) as shown [here](https://stackoverflow.com/a/67628066/7121513). – Ivan Shatsky May 28 '22 at 15:05
2

If you want your URL to remain as /privacy in your browser, you can do something like this:

# Handle the case with trailing slash
location /privacy/ {
    return 302 /privacy;
}
# Alias to PDF file and specify content type for browser to display instead of download
location /privacy {
    alias /webapps/app/static/downloads/privacy_policy.pdf;
    default_type application/pdf;
}
speed488
  • 302
  • 1
  • 10