Ruby on rails 两个位置的Nginx X-Accel-Mapping标头
一些背景: 我希望能够从Rails应用程序触发文件下载,并通过Nginx下载文件 我可以在一个文件夹中使用,但不能在两个不同的文件夹中使用 我使用的是如下内容:Ruby on rails 两个位置的Nginx X-Accel-Mapping标头,ruby-on-rails,nginx,Ruby On Rails,Nginx,一些背景: 我希望能够从Rails应用程序触发文件下载,并通过Nginx下载文件 我可以在一个文件夹中使用,但不能在两个不同的文件夹中使用 我使用的是如下内容: # nginx config location /filestorage/ { internal; alias /mnt/filestorage/; } proxy_set_header X-Accel-Mapping /mnt/filestorage/=/filestorage/; # control
# nginx config
location /filestorage/ {
internal;
alias /mnt/filestorage/;
}
proxy_set_header X-Accel-Mapping /mnt/filestorage/=/filestorage/;
# controller code (e.g. app/controllers/downloads_controller.rb)
send_file('/mnt/filestorage/my_file.zip')
我尝试了以下方法来支持另一个文件夹:
location /filestorage/ {
internal;
alias /mnt/filestorage/;
}
location /filestorage2/ {
internal;
alias /mnt/filestorage/;
}
proxy_set_header X-Accel-Mapping "/mnt/filestorage/=/filestorage/ /mnt/filestorage2/=/filestorage2/";
# controller code (e.g. app/controllers/downloads_controller.rb)
send_file('/mnt/filestorage/my_file.zip')
send_file('/mnt/filestorage2/another_file.zip')
但是,这不起作用,两个文件夹中的文件都不可用
是否有方法将位置传递到X-Accel-Mapping标头?太晚了,但Workaround可能是这样的。 (在application.rb或初始值设定项中)
config.middleware.swap(
::Rack::Sendfile,
::Rack::Sendfile, 'X-Accel-Redirect',
[['file_path', 'nginx_internal'],
['....','.....']]
)