Stan Zeez
Stan Zeez

Reputation: 1188

Serve pdf file by location in nginx

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;
}

Upvotes: 2

Views: 10449

Answers (2)

speed488
speed488

Reputation: 306

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;
}

Upvotes: 2

Stan Zeez
Stan Zeez

Reputation: 1188

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;
}

Upvotes: 13

Related Questions