0

I'd like to serve a unique pdf file by location in nginx.

I followed the instruction here:

https://stackoverflow.com/questions/42023339/serve-pdf-file-by-location-in-nginx

and I did:

location /xxx-privacy-disclosure/ {
    alias /var/www/public_html/domain.net/xxx-privacy-disclosure/;
    index xxx-privacy-disclosure.pdf;
}

Everything is working except a .pdf file is downloaded (without the filename)

How can I fix this?

1 Answers1

0

Drop the index directive and replace it with, e.g. return 302 to make a redirect.

location /xxx-privacy-disclosure/ {
    alias /var/www/public_html/domain.net/xxx-privacy-disclosure/;
    return 302 xxx-privacy-disclosure.pdf;
}
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Hi Michael, I tried and in the url the redirection works (the url is the whole path including the pdf) but I receive a too-many-redirect error in chrome – Ponzio Pilato May 27 '21 at 21:24
  • I solved moving the pdf in another folder (in this case root) respect the "location" directive. And it works like a charm! Thanks a lot! I'm sorry but I don't have enough reputation for add "useful" state – Ponzio Pilato May 27 '21 at 21:26