Url rewrite for restful url

I have a Rails web app which has static files under dynamic restful
urls. For example:

/projects/1/attachments/some_file.xls

I want to setup Nginx to redirect to the static file on the server:

/public/attachments/1/some_file.xls

Where 1 is the dynamic project id.

How would the location block and rewrite statement look for the Nginx
config file?

StackOverflow link:

On Wed, Aug 08, 2012 at 08:30:57PM +0200, Edward S. wrote:

Hi there,

/projects/1/attachments/some_file.xls

I want to setup Nginx to redirect to the static file on the server:

/public/attachments/1/some_file.xls

Where 1 is the dynamic project id.

If you want requests like /projects/N/attachments/F to return the
content
of the file /public/attachments/N/F, then “alias” is probably the way
to go.

http://nginx.org/r/alias

location ~ ^/projects/(\d+)/attachments/(.*) {
alias /public/attachments/$1/$2;
}

Good luck with it,

f

Francis D. [email protected]