1

In nginx is there a way to conditionally serve a file with different expires headers depending on when the file was last modified? For example, if foo was modified within the last week then I want it to expire in a few hours, otherwise I want it to expire in a few days.

1 Answer 1

0

Browsers are probably already supposed to have the functionality you describe, so, there's really not that much point implementing it within nginx.

Standard nginx has the expires directive, which lets you use several kinds of static no-comparison offset-style expressions, but not the dynamic ones you describe.

I don't think any of the standard modules that are compiled by default into nginx can do what you request here — dynamic expires, with a varying offset depending on how long ago the file was modified.

However, there is an ngx_http_perl_module, which is an official experimental perl module directly from the makers of nginx, which lets you use the resourceful perl language directly from within the nginx configuration file.

Note that this http_perl_module is not compiled by default for obvious reasons (obviously requires perl etc), and is considered highly experimental — use with care.

2
  • The Lua module should be built in, and that would work as well. Commented Dec 1, 2013 at 3:52
  • Not yet in nginx, but it's already available in the kernel. So, yes, you could probably tie your in-kernel lua-based kernel module in NetBSD with the bpf(4) interface, and look for packets requesting certain files, find their mtime in the vfs(9) layer, and patch the Expires HTTP response header in the outgoing packets as you please. Care to volunteer a bounty for the work needed to implement such a solution? Commented Dec 1, 2013 at 4:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.