Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
        server_name  127.0.0.1;
        passenger_enabled on;
        root    /home/voodoo/work/reader/public;

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

          proxy_pass http://127.0.0.1:3001/;
        }

    }

And a respective rails controller

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

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 127.0.0.1 at 2013-01-13 00:17:10 +0530
Processing by ReaderController#resource as XML
  Parameters: {"id"=>"229", "resource"=>"OPS/cover"}
Client Ip Address 127.0.0.1
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 127.0.0.1 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

 
discard

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

Browse other questions tagged or ask your own question.