Status code in nginx try_files directive
Solution 1:
Your examples have infinite loop.
Probably, you want something like this:
error_page 404 @error404;
error_page 500 @error500;
error_page 503 @error503;
location @error404 {
root /path_to_static_root/;
try_files /$host/404.html /404.html =404;
}
location @error500 {
root /path_to_static_root/;
try_files /$host/500.html /500.html =500;
}
location @error503 {
root /path_to_static_root/;
try_files /$host/503.html /503.html =503;
}
..and it will work faster then with variables.
NGINX FAQ: Is there a proper way to use nginx variables to make sections of the configuration shorter, using them as macros for making parts of configuration work as templates?
Update:
The community wiki is not documentation. From the official documentation:
$status
- response status (1.3.2, 1.2.2)
@ http://nginx.org/en/docs/http/ngx_http_core_module.html#variables