Nginx setting to force PDF file to be downloaded instead of viewing in the browser

In nginx, when user click on a PDF link, if you want the file to be downloaded instead of showing directly on the web browser, we have to default the MIME type of the pdf files from application/pdf to application/octet-stream. So you can add the following lines in your nginx settings:

# force pdf files to be downloaded
location ~* (.*\.pdf) {
    types { application/octet-stream .pdf; }
    default_type application/octet-stream;

Sure you can customise the location rule.