0

How can I specify in my conf file so that

given request: /find/{xyz}

nginx would search for and serve file with name: some_arbitrary_prefix.{xyz}.html where some_arbitrary_prefix might be any random string before dot?

EDIT: I don't understand, why regex tag was deleted from question? In other words, I guess what I'm asking is: can one use regex to filter target files rather than locations?

Twice_Twice
  • 527
  • 4
  • 16

1 Answers1

2

You can use a regular expression with location to extract the part of the URI following /find/, and then use try_files to construct the path to the filename.

For example:

location ~ ^/find/(.*)$ {
    root /path/to/folder;
    try_files /someprefix.$1.html =404;
}
Richard Smith
  • 45,711
  • 6
  • 82
  • 81
  • Sorry, I failed to mention that `someprefix` can be anything (edited my question) and unknowable. Can I use something like `try_files /(.*).$1.html =404` in config? – Twice_Twice Mar 03 '21 at 11:40