Always serve index without trying file nginx


Is there a better way of serving a random file?

mydomain.com/m1/whatever.webp – should serve random file because whatever.webp doesn’t exist.

location /m1/ {
        root  /home/my/public_html/;
        try_files $uri $uri/ /m1/;
        random_index  on;
}

What I want nginx is not to try_files (would save file lookup processing?) and just serve random file.

Also how do I configure it to serve random file from any directory – mydomain.com/m1/some/dir/whatever.webp – should serve random file from /home/my/public_html/m1/some/dir/