Welcome! Log In Create A New Profile

Advanced

Need help setting up nginx for secure static asset delivery using X-Accel-Redirect

Posted by rameshvel 
Need help setting up nginx for secure static asset delivery using X-Accel-Redirect
January 12, 2013 04:02PM
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\sources\:book_id\remaining_path".

only the "rails_root\books\sources" is constant, remaining always change. ex

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

i tried setting up the nginx using the following configuration


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/;
}

it successfully detects the request and passing it to the rails. on rails am doing

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

It returns the file info back to nginx, but eeems rails doesnt understand the X-Accel-Mapping of my config. so when nginx trying to read the file, this error happens

ActionController::RoutingError (No route matches [GET] "/home/mango/work/mangoreader/books/sources/229/OPS/cover.xml"):

I strongly believe this is due to the incorrect X-Accel-Mapping in nginx. But cant figure out what. can somone help me out. I am struck with this for last few hours.

Thanks
Ramesh
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 72
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready