Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to serve static contents via nginx & rails using X-Accel-Redirect. My actual static content directort located at rails root folder like this rails_root\books. This is my nginx config file mapping the url with the actual file location

server {
        listen       3000;
        passenger_enabled on;
        root    /home/voodoo/work/reader/public;

        location ~ /read/*./.* {
          alias /home/voodoo/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;

          passenger_pass_header X-Accel-Redirect;
          passenger_set_cgi_param  HTTP_X_ACCEL_MAPPING   /read/=/home/voodoo/work/reader/books/sources/;



And a respective rails controller

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

The controller is successfully triggered with the X-Accel-redirect by nginx, and conroller returns the data. This is the log

Started GET "/reader/229/OPS/cover.xml" for at 2013-01-13 00:17:10 +0530
Processing by ReaderController#resource as XML
  Parameters: {"id"=>"229", "resource"=>"OPS/cover"}
Client Ip Address
Sent file /home/voodoo/work/reader/books/sources/229/OPS/cover.xml (0.2ms)
Completed 200 OK in 7ms (ActiveRecord: 0.5ms)
cache: [GET /read/229/OPS/cover.xml] miss

But the next log is totally different, and the request stops right there

Started GET "/home/voodoo/work/reader/books/sources/229/OPS/cover.xml" for at 2013-01-13 00:17:10 +0530

ActionController::RoutingError (No route matches [GET] "/home/voodoo/work/reader/books/sources/229/OPS/cover.xml"):
  actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'

It throws an error RoutingError (No route matches [GET] (actual file path). After some digging i found that, this error can happen because of config.serve_static_assets = false in production.rb. But its actually true in my config.

I have tested changing passenger in standalone mode, and with nginx. I always gets the same error. I am totally struck here. Can someone help me out?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.