Nginx try

  
 

try_files is a new function added after nginx0.6.36 to search for N files in the specified directory. If fileN is not found, the location specified in fallback is called to process the request. Personally think that as the core content of nginx, it can partially replace the cumbersome rewrite function, I used it in the rewrite rewrite of wp super cache, and also achieved good results.


try_files

Syntax: try_files file1 [file2 ... filen] fallback

Default: None

Scope: Location

The function of this command is to receive multiple paths as parameters. If the resource of the current path cannot be found, the next path will be automatically found. If the requested static resource does not exist, the specified location of the fallback will be requested. Dynamic processing on the background server.

Simple example: location /{try_files index.html index.htm @fallback;}

location @fallback {root /var/www/error;index index.html;} author's The blog has just been established, wp super cache is an indispensable plugin, but the default supercache is for .apaccess of apache, the configuration under nginx is as follows:

set $cache /wp-content/cache /supercache/$host;#wp-super-cache path listen 80; server_name _;location /{root /home/html/s0001/domains/$host;index index.php index.html;#Direct call gzip compression Html static file add_header Content-Type "text/html; charset=UTF-8";add_header Content-Encoding "gzip";try_files $cache/$uri/index.html.gz @proxy;}#All static files Both are processed by nginx and compressed with gzip output location ~* \\.(jpg

Copyright © Windows knowledge All Rights Reserved