File Checking Rewriting and Handing off to Back End
David.Legg at smithelectric.com
Fri Nov 8 11:51:36 UTC 2013
We're starting to make more and more heavy use of Nginx having shifted from Apache, mostly in handing off to backends running Puma and php-fpm. However, wherever possible we naturally want Nginx to serve what it can with only the bare minimum hitting the back end. However, this generally means writing more and more complex rules.
I have a requirement for Nginx to serve a file if it exists or hand off to a Rails controller. The URI is data?x=X&y=Y&z=Z which at the moment goes direct to a Rails controller, sends the file back directly and saves a static png file in the process. What I need to do in Nginx is take the parameters of the URI and check whether the file /data/X_Y_Z.png exists. If not hand off to the Rails controller. This means that Nginx serves files and only hands off to Rails when needed. It also means that I need to formulate the file that I want to check from the get parameters ($args_parameter?) in the Nginx config.
I've been trying various things out through try_files which I think is the right area to be looking at. Something like:
try_files /tiles/$args_z_$args_x_$args_y.png proxy_hand_off
Any ideas how I could do this? Anything would be appreciated including an easier way I haven't thought of. I naturally want to keep 'if' statements down to a minimum, if any at all.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nginx