What is = in try_files?

What does try_files $uri $uri.html = @second do instead of try_files $uri $uri.html @second what is = for?

The directive syntax is:

try_files file1 file2 ... fallback;
  1. Nginx checks each fileN in order (relative to root or alias).
  2. If a match is found, it serves that file immediately.
  3. If none match, it processes the final argument:
    • If it starts with =, it is an HTTP status code.

    • Otherwise, it’s interpreted as an internal redirect to a URI (location block).

Let’s keep watch in your config file.
try_files $uri $uri.html = @second;

This means:

  1. Check if there is a file at $uri (e.g., /about).

  2. If not, try $uri.html (e.g., /about.html).

  3. If neither exists → return HTTP status code @second :cross_mark: ← invalid, because @second is not a number.

:backhand_index_pointing_right: Actually, this won’t work. =something only accepts numeric codes (like =404, =403, =500).

try_files $uri $uri.html @second;
Check $uri.

  1. Check $uri.html.
  2. If neither exist → internally redirect to the named location @second.
1 Like

Our docs actually have quite a bit of documentation and examples for try_files.

The tl;dr is that the last parameter, uri or =code are used to determine what NGINX should do if the files are not found. If you use a “code”, NGINX will return that status code and the associated error page if there is one defined.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.