Nginx: Difference between revisions

imported>Exyi
Link to oficial docs
imported>Kvtb
This no longer applies since NixOS 19.09. In 19.09 and newer versions, this is already handled by a patched version of nginx. The etag patch is applied by default, so no intervention is required
Line 208: Line 208:
<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>


== See more ==
== See more ==
* [http://nginx.org/en/docs/ Official Documentation]
* [http://nginx.org/en/docs/ Official Documentation]