I´m trying to serve a pdf file by making a configuration in nginx but I get the following error in the page: 404 Not Found The configuration is like this: server { listen 3002; index index.html; server_name _; location / { root /var/www/html/pdf_carpet; try_files $uri /index.html = 404; } } pdf_carpet is where the pdf file is. What could I do or change to be able to serve a pdf file in nginx? P.S. It works with html files. asked Jan 23, 2022 at 16:11 Coder20Coder20651 silver badge7 bronze badges 5 Here is the full location block that should show the PDF file in the browser window under the http://:3002/pdf_carpet URL: location = /pdf_carpet { alias /var/www/html/pdf_carpet/file.pdf; default_type application/pdf; add_header Content-Disposition 'inline'; } Update If an URI for accessing the PDF file ends with the slash (or it is a root URI as a special case), the above config would not work since an index file name will be appended to such an URI by the nginx (making location = /path/ { ... } not match the $uri internal nginx variable). For such a case another technique can be used: location = / { root /var/www/html/pdf_carpet; rewrite ^ /file.pdf break; add_header Content-Disposition 'inline'; } answered Jan 23, 2022 at 18:12 Ivan ShatskyIvan Shatsky15.8k2 gold badges25 silver badges51 bronze badges 5 Start asking to get answers Find the answer to your question by asking. Ask question Explore related questions See similar questions with these tags.