我在文件夹/memos/items/有一个备忘录集合单个备忘录用于包含一个HTML标头部分的SSI包含语句,直到包括开头的<body> ,随后是备忘录内容的HTML代码,最后还有一个SSI包含了包含closuresHTML文档代码的页脚声明,如下所示:
<!--# include file="/memos/header.html" --> Dies ist ein <i>Testeintrag</i>. <blockquote> Man soll den Tag nicht vor dem Abend loben </blockquote> <!--# include file="/memos/footer.html" -->
这工作得很好,但我不喜欢单个项目文件中的SSI语句。 我宁愿指示nginx自动为页眉和页脚提供类似的configuration
location ~ /memos/[\w-]+$ { sendfile /memos/before.html; sendfile $request_filename; sendfile /memos/after.html; }
这可能吗? 是否有一个nginx模块提供一个指令sendfile工作方式sendfile ?
优点是:
grep 。 编辑(2016/07/01)
同时,通过简单地改变视angular,我发现了SSI解决scheme具有上述优势(即仅提供内容的项目文件,没有ssi标签):在每个单独的项目文件中,不包括页眉和页脚,而是包含项目文件在一个主模板中。
受nginx网站上的提议的启发; 我configuration
location /memos/ { ssi on; default_type text/html; location ~ /memos/([\w-]+)$ { set $inc /memos/items/$1; rewrite ^ /memos/template.html break; } }
并在master template.html使用variables$inc :
<!doctype html> <html lang="de"> <head> <meta charset="utf-8"> ... </head> <body> <div id="content"> <!--# include file="$inc" --> </div> <script src="main.js"></script> <script src="items.js"></script> </body> </html>
然而,我不会closures这个话题,因为我仍然对原始问题感兴趣,是否可以指示nginx将一个响应组合成一个文件序列。
您可以使用在构build时需要启用的添加模块( ngx_http_addition_module ) (– --with-http_addition_module ):
location / { add_before_body /before_action; add_after_body /after_action; }
请注意,它不允许堆叠任意数据,而是提供在主响应之前和之后添加内容的function。 通过使用带有另一条添加指令的位置作为add_*_body来堆叠其他调用也是可能的,但是我没有尝试过 – 这肯定会降低configuration的可读性。