# Nginx, provide file from a folder or create it if not there

**URL:** <https://www.ruby-forum.com/t/nginx-provide-file-from-a-folder-or-create-it-if-not-there/184422>\
**Category:** NGINX\
**Created:** [March 2, 2010, 11:12am UTC](https://www.ruby-forum.com/t/nginx-provide-file-from-a-folder-or-create-it-if-not-there/184422 "2010-03-02T11:12:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [March 2, 2010, 11:12am UTC](https://www.ruby-forum.com/t/nginx-provide-file-from-a-folder-or-create-it-if-not-there/184422/1 "2010-03-02T11:12:59Z")

</div>

Hi,

I’d like to add some extra logic to the location rules in my Nginx  
server.

I have an application that creates a binary file based on client  
requests. It only sends back a binary file using send\_file method. The  
contents of the binary file depend on a short key that is sent in the  
body of a post request by the client.

When the application makes the file it stores it in a given folder.

I’d like to add a rule in Nginx so that depending on the key in the body  
it would either directly provide a file with a given name.bin (if  
existing in the folder). But if it is not existing it would actually use  
the rails app to generate it.

I know I can check the body of the request with $request\_body and use  
that in an if clause inside location rules. But how to make the decision  
to provide the file if existing or send the request to rails otherwise?

Cheers.
