我试图让Nginx使用x-sendfile
我有一个自定义的symfony(3.4)应用程序,必要的文件是:
所调用的网址类似于/media/1/download/video-title
。
在前端控制器中,我需要在Symfony中以以下方式激活XSendfile:
BinaryFileResponse::trustXSendfileTypeHeader();
我的nginx虚拟主机看起来像这样:
# ...
root /path/to/myproject.com/web;
location /admin {
index admin.php;
try_files $uri @rewriteadmin;
}
location @rewriteadmin {
rewrite ^(.*)$ /admin.php/$1 last;
}
location / {
index website.php;
try_files $uri @rewritewebsite;
}
# expire
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff|woff2|eot|ttf)$ {
try_files $uri /website.php/$1?$query_string;
access_log off;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
# I tried to set the /media to internal
location /media {
internal;
}
location @rewritewebsite {
rewrite ^(.*)$ /website.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(website|admin|app|app_dev|config)\.php(/|$) {
include fastcgi_params;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SYMFONY_ENV dev;
fastcgi_param 'X-Sendfile-Type: x-accel-redirect';
}
似乎没有任何作用,因为当我手动设置$ request-> headers-> set时,X-Sendfile-Type也位于$ request-> servers下,但它仍然失败。并在nginx http配置中激活了sendfile。
由于PHP应用程序需要进行一些安全检查,因此需要调用PHP。