Symfony 5:尝试使用 查看<a>文件时找不到错误文件



在我的公用文件夹中有一个pdf文件夹,里面有很多pdf。我正在使用

<a href="/pdf/1.pdf" download="1.pdf"> 1</a>

因此,当任何人点击1时,他们都可以下载该文件。我甚至尝试过使用asset来做,但出现的问题是我可以在本地主机上下载,但不能在实际服务器上下载。它显示Failed No文件。更多信息,我使用Nginx。

server {
server_name xxx.xxx.com;
root /var/www/xxx.xxx.com/public;
index index.php;
location / {
try_files /index.php /index.php;
include snippets/fastcgi-notry-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
location ~ .css {
add_header  Content-Type    text/css;
} 
location ~ .js {
add_header  Content-Type    application/x-javascript;
}

正如您在配置中看到的,.css和.js文件扩展名也有例外,它们被用作具有适当内容类型的静态文件。这就是为什么你可以看到你所有的风格和js代码。很明显,您还必须添加将用作静态文件的文件扩展名:

location ~ .pdf {
add_header  Content-Type    application/pdf;
}

最新更新