Server Side Includes (SSI)
SSI commands enable you to include files within other pages.
At its most basic, you can include files within other ones so as not to repeat yourself.
Start by enabling SSI:
"https://{default}/":
type: upstream
upstream: "app:http"
ssi:
enabled: true
Then create a file you want to include elsewhere:
<p>This content can be reused</p>
And include it in another file:
<body>
<p>This content is unique to this page.</p>
<!--#include virtual="includes/example.html" -->
</body>
And your final rendered page includes the other file:
<body>
<p>This content is unique to this page.</p>
<p>This content can be reused</p>
</body>
Caching and dynamic content
You can use SSI to have caching and dynamic content in one. So one file is cached, while another updates dynamically.
For example, you can activate SSI on one route with cache disabled and enable cache on another route:
"https://{default}/":
type: upstream
upstream: "app:http"
ssi:
enabled: true
cache:
enabled: false
"https://{default}/cache":
type: upstream
upstream: "app:http"
cache:
enabled: true
Then create a page that displays the current date and time and is cached for 60 seconds (the example uses PHP, but any server-side language would work):
<?php
header("Cache-Control: max-age=60");
echo date(DATE_RFC2822);
Then you could have a page with dynamic content that includes this file:
<?php
echo date(DATE_RFC2822);
?>
<!--#include virtual="cache/example.php" -->
Then you can visit index.php
and refresh the page a few times.
You see the first number updating to the current time, while the second (included) one only changes every 60 seconds.
For more on SSI, see the nginx documentation.