I'm returning a pdf file at a specific location in nginx. When someone goes to mysite.com/resume
, I want my resume.pdf
to be returned but at the redirected url of mysite.com/resume.pdf
(so that the browser will show download/print/etc buttons related to pdfs).
What I have below returns the pdf since resume.pdf
is in /dir/to/contents/
, but as mysite.com/resume
, not mysite.com/resume.pdf
. How can I achieve this kind of redirect?
server {
listen 80;
listen [::]:80;
server_name mysite.com;
root /dir/to/contents;
location / {
index site.html;
}
}
- Edit: address first comment
/resume
to/resume.pdf
.resume.pdf
is in the dir specified by theroot
directiveresume.pdf
toresume
? Remark the your browser doesn't care if the URL of the page ends in.pdf
, what matters is the media type sent by nginx. On the other hand nginx guesses the media type based on the file extension. So what URL do you want to have and what do you want to call the file on the disk? I assume you want the content served asapplication/pdf
.