Nginx: Difference between revisions
imported>Amarandus m Add some references and third party sites for testing your service and applying to HSTS preloading |
imported>Ledettwy Add entry for serving static files from /nix/store over nginx and having caching work correctly |
||
| Line 149: | Line 149: | ||
<hr /> | <hr /> | ||
== Correct Caching when Serving Static Files from /nix/store == | |||
Since the dates for all files in /nix/store are set to 1 second after the unix epoch, attempting to serve them over nginx can result in caching issues. etags can be used to resolve this, but nginx's built-in etags depend on the file modification time and size, which isn't good enough for us. To have caching work reliably, we'll construct our own etag: | |||
<syntaxhighlight lang="nix"> | |||
locations."/my/static/file.txt" = | |||
let file = pkgs.writeText "file.txt" "this is a static file!"; | |||
in | |||
{ alias = file; | |||
extraConfig = '' | |||
etag off; | |||
add_header etag "\"${builtins.substring 11 32 file.outPath}\""; | |||
''; | |||
} | |||
</syntaxhighlight> | |||