The NGINX directives needed for Yavli Resilience should be placed inside the server directive for your site. Almost all sites can use one of the following proxy solutions, which one depends on your existing NGINX configuration, and may still need certain customization to work with your particular set up.
Yavli staff is always happy to help you set this up. You may send us your existing NGINX configuration file, and we will implement the proxy directives in it for you.
location ~.*\.(jpg|jpeg|png|gif|js|css)$ { error_page 404 = @yavli; } location @yavli { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_pass http://steg.yavli.com; }
NGINX configurations often contain location blocks matching all image suffixes (jpg / png / gif) which it may apply things like custom caching headers. If this is the case in your NGINX config file, you will need to nest the Yavli directives inside of the pre-existing directives. Yavli staff is always happy to help if you are uncertain on how to do this. The end result may look something like this:
location ~.*\.(jpg|jpeg|png|gif|js|css|pdf|other|suffxies)$ { ...other pre-existing directives... location ~.*\.(jpg|jpeg|png|gif|js|css)$ { error_page 404 = @yavli; } } location @yavli { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_pass http://steg.yavli.com; }
Some NGINX configurations already make use of NGINX’s proxy functionality in order to create a system where image requests go through a logic chain like this:
Location based proxying (solution 1 and 2) will not work with this type of NGINX configuration, instead we use an if-clause at the end of the existing proxy-logic. This set up may look something like this:
location ~.*.(jpg|jpeg|png|gif|js|css|etc)$ { expires 7d; try_files $uri @backend; } location @backend { proxy_pass http://appserver; proxy_intercept_errors on; if ($uri ~ .*\.(jpg|jpeg|png|gif|js|css)$) { error_page 404 = @yavli; } } location @yavli { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_pass http://steg.yavli.com; }
Yavli Staff is always happy to help you configure the proxy directives. Send us your current NGINX site configuration file, and we will determine which method will work best for you.