Status code in nginx try_files directive
        Posted  
        
            by 
                Hamish
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Hamish
        
        
        
        Published on 2012-06-07T22:03:25Z
        Indexed on 
            2012/06/07
            22:42 UTC
        
        
        Read the original article
        Hit count: 382
        
nginx
Is it possible to use the current status code as a parameter in try_files?
For example, we try to provide a host specific 503 static response, or a server-wide fallback if it wasn't found:
error_page 503 @error503;
location @error503 {
    root /path_to_static_root/;
    try_files /$host/503.html /503.html =503;
}
There are a number of these directives, so it would be convenient to do something like:
error_page 404 @error
error_page 500 @error
error_page 503 @error
location @error {
    root /path_to_static_root/;
    try_files /$host/$status.html /$status.html =$status;
}
But the Variables documentation doesn't list anything that we could use to do this.
Is it possible, or is there an alternative way to do this?
© Server Fault or respective owner