Hello,
with dynamic scripts, it is not possible to do with server configuration (it can only be done with additional feature added to the scripts code, which nobody does usually). The reason of this is that pages generated by scripts are "real-time" pages.
As for static pages (html) - the lastmod time is sent automatically by web-servers for them and they should work fine.