Server-Side Includes

Server-Side Includes (or SSI) are a simple interpreted server-side scripting language that has a set of directives (or commands) that are written in HTML pages and processed by the web server when requested. It allows you to make basic dynamic content on your website and it's very similar to CGI and PHP but has many limitations and is not entirely stable.

NOTE: Because we're using Nginx as a web server, some SSI commands that are from Apache or from other web servers will not work here.

Usage

To use SSI, you need to first make a HTML page or edit any other that you have on your igloo. Most guides recommend using ".shtml" as file extension name than of ".html"/".htm" for make SSI-only webpages but on Nginx this doesn't matter and it will continue to work anyway.

SSI directives are enclosed in HTML comments but with an hash symbol and with the directive to execute. Here's an example of an HTML page with a SSI command that inserts the current date and time of the server:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Current Date with SSI</title>
    </head>
    <body>
        <p>The current date is: <!--#echo var="DATE_LOCAL" --></p>
    </body>
    </html>

When this webpage is saved and loaded, the SSI command will be processed on the server side, and the current date and time will be inserted into the page.

This other example shows the inclusion of HTML pages for headers and footers (both saved on a "include/" directory):

    <!DOCTYPE html>
    <html>
    <head>
        <title>HTML Includes with SSI</title>
    </head>
    <body>
        <!--#include file="include/header.html"-->
        <h3>Welcome to my homepage!</h3>
        <p>Thank you very much for checking it!</p>
        <!--#include file="include/footer.html"-->
    </body>
    </html>

This only works if the HTML documents are stored inside the "public_html" root directory, otherwise they cannot be loaded correctly due to Nginx limitations. See this tree directory structure diagram as an example:

    public_html/
        ├── include/
        │   ├── footer.html
        │   └── header.html
        ├── index.html
        └── about.html

Available commands

This is a tiny list of SSI commands on Nginx:

See the official Nginx SSI module documentation for a full list of available commands (and examples).