我正在嘗試通過在 nginx 中進行配置來提供 pdf 檔案,但我在頁面中收到以下錯誤:404 Not Found
配置是這樣的:
server {
listen 3002;
index index.html;
server_name _;
location / {
root /var/www/html/pdf_carpet;
try_files $uri /index.html = 404;
}
}
pdf_carpet 是 pdf 檔案所在的位置。
為了能夠在 nginx 中提供 pdf 檔案,我可以做什么或改變什么?
PS 它適用于 html 檔案。
uj5u.com熱心網友回復:
這是應在http://<your_domain_or_IP>:3002/pdf_carpetURL下的瀏覽器視窗中顯示 PDF 檔案的完整位置塊:
location = /pdf_carpet {
alias /var/www/html/pdf_carpet/file.pdf;
default_type application/pdf;
add_header Content-Disposition 'inline';
}
更新
如果訪問 PDF 檔案的 URI 以斜杠結尾(或者它是根 URI 作為特殊情況),則上述配置將不起作用,因為 nginx 會將索引檔案名附加到此類 URI(使location = /path/ { ... }不匹配所述$uri內部nginx的變數)。對于這種情況,可以使用另一種技術:
location = / {
root /var/www/html/pdf_carpet;
rewrite ^ /file.pdf break;
add_header Content-Disposition 'inline';
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420968.html
標籤:
