2013-01-12 29 views
0

我试图通过使用X-Accel-Redirect的nginx & rails来提供静态内容。位于我的实际静态内容目录轨道根文件夹这样设置nginx X-Accel-Mapping for rails安全静态内容传送

- "rails_root\books\sources\:book_id\remaining_path". 

只有rails_root\books\sources是恒定的,其余部分总是在不断变化。离

-app\books\sources\111\oep\cover.html 
    -app\books\sources\111\oep\images\xx.png 

我尝试使用以下配置

location ~ /readbook/*./.* { 
     internal; 
     alias /home/vooodoo/work/reader/books/sources/$1/$2; 
    } 

    location/{ 
     proxy_redirect off; 

     proxy_set_header Host    $http_host; 
     proxy_set_header X-Real-IP   $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

     proxy_set_header X-Sendfile-Type X-Accel-Redirect; 
     proxy_set_header X-Accel-Mapping /readbook/=/home/vooodoo/work/reader/books/sources/; 

     proxy_pass http://127.0.0.1:3001/; 
    } 

它成功地检测到所述请求建立的nginx并将它传递给所述导轨。在轨道上做

class ReaderController < ApplicationController 
     def resource 
      send_file "#{Rails.root}/books/sources/"+ params[:id] + "/" + params[:resource] + "." + params[:format] 
     end 
end 

它将文件信息返回到nginx,但似乎rails不理解我的配置的X-Accel-Mapping。所以当nginx的尝​​试读取这个文件,这个错误发生

的ActionController :: RoutingError(无路由匹配[GET] “/家/巫术/工作/读卡器/书籍/资源/ 229/OPS /套。 xml“):

我坚信这是由于incorrect X-Accel-Mapping in nginx。但不知道什么。有人可以帮我吗。最近几个小时我感到震惊。

+0

是你能找到解决办法? – Sheharyar

回答

0

我相信/readbook=/...应该是...=/readbook/

0

X-Accel-Mapping配置错误,试试这个:

location ~ /readbook/*./.* { 
    internal 
    alias /home/vooodoo/work/reader/books/sources/$1/$2; 
} 

location/{ 
    ... 
    proxy_set_header X-Sendfile-Type X-Accel-Redirect; 
    proxy_set_header X-Accel-Mapping /home/vooodoo/work/reader/books/sources/=/readbook/; 
    ... 
}