設定ngnix下的檔案在瀏覽器端直接下載而不是被瀏覽器預設開啟
阿新 • • 發佈:2019-01-05
server {
listen 443 ssl;
server_name localhost;
ssl_certificate key/1__.hexunzc.com_bundle.crt;
ssl_certificate_key key/2__.hexunzc.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
location ~ ^/attach/product/financing/(.*)$ {
add_header Content-Disposition "attachment; filename=$1";
}
listen 443 ssl;
server_name localhost;
ssl_certificate key/1__.hexunzc.com_bundle.crt;
ssl_certificate_key key/2__.hexunzc.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
add_header Content-Disposition "attachment; filename=$1";
}
}
在nginx.conf檔案中新增紅色部分的配置,即當 /attach/product/financing/ 這個目錄下的檔案被請求時加上一個頭部資訊告訴瀏覽器直接下載檔案而不是開啟,比如pdf