I was wondering if it is possible to have nginx rewrite a URL to point to the most recent (last naturally sorted) version of a file? Basically, I have a directory full of revisions of a file, like this:


And I would like to rewrite a request for "file.txt" to the most recent version of that file. This is kind of what I want to do:

root /var/files;
rewrite file.txt $(ls -v /var/files | tail -1);

Or a 302 would be good too!

location file.txt {
    return 302 $(ls -v /var/files | tail -1);

Please also note that symlinking is not an option :( I would like to have this handled by nginx, or some extension to nginx.

  • 2
    Have you considered Nginx's Lua support for this? – ceejayoz Feb 10 at 18:53
  • @ceejayoz I have no idea what that is! I will look into it. Thanks. – Jared Brandt Feb 10 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.