Server Side Includes(ngx_http_ssi_module)

 

 


Module Settings

 

Nginx Settings

location / {
    ssi on;
    ssi_types text/html;
    ...
}

ssi_types

Default: ssi_types text/html;

Enables processing of SSI commands in responses with the specified MIME types in addition to “text/html”

Default page settings

    if (!-f $request_filename) {
        rewrite ^ /index.html last;
    }
    if (!-f $document_root$inc.html) {
        return 404;
    }

index.html

<h2>Server information</h2>
<p>Server local time: <!--#echo var="DATE_LOCAL" --></p>

<h2>Visitor information</h2>
<p>Visitor IP address: <!--#echo var="REMOTE_ADDR" --></p>

<pre>
<!--#include file="uptime.txt" -->
</pre>

 


SSI Commands

 

format

<!--# command parameter1=value1 parameter2=value2 ... -->

block

# Defines a block that can be used as a stub in the include command.

# The block can contain other SSI commands.  

<!--# block name="one" -->
test
<!--# endblock -->

include

file

# specifies an included file

<!--# include file="footer.html" -->

virtual

# specifies an included request

<!--# include virtual="/remote/body.php?argument=value" -->

要配合 location 使用

location /remote/ {
    ...
}

The maximum size of the response was set with the

  • proxy_buffer_size
  • memcached_buffer_size
  • fastcgi_buffer_size
  • uwsgi_buffer_size
  • scgi_buffer_size directives

stub

block whose content will be output if the included request results in an empty body or if an error occurs during the request processing

<!--# include virtual="/remote/body.php?argument=value" stub="test" -->

set

instructs to write a successful result of request processing to the specified variable

<!--# include virtual="/remote/body.php?argument=value" set="one" -->

echo

Outputs the value of a variable.

<!--# echo var="name" default="test" -->

var

the variable name.

default

a non-standard parameter that sets a string to be output if a variable is undefined.

By default, “(none)”

set

# Sets a value of a variable.

if ... elif ... else

<!--# if expr="..." -->
...
<!--# elif expr="..." -->
...
<!--# else -->
...
<!--# endif -->

 

 

 

 

 

 

Creative Commons license icon Creative Commons license icon