Enable SSI configuration to make shtml support include common headers and footers

When writing many static files of a project, you can use include to introduce the common header/footer/sidebar of the page as a public, independent and single file to each page like a development language such as php, so that when you modify the common parts of these pages, you can Modify the corresponding independent file once, and you can update the entire site, once and for all!

What is shtml?

Using the html file extension of (Server Side Include), SSI (Server Side Include), usually called "Server Side Include" or "Server Side Include", is a server-based web page creation technology, and its file extension is by default. The names are .stm, .shtm, and .

It is a server-based web page production technology. Most (especially based on Unix platforms) web servers such as Netscape Enterprise Server support SSI commands.

The reason it works is: use SSI instructions to include text, image or code information into a web page before the page content is sent to the client. Using SSI is an easy way to have content that recurs in multiple files, just by putting the content in one include file instead of having to enter it all. The include file is invoked with a very simple statement that instructs the web server to insert the content into the appropriate web page. Also, when using include files, all changes to the content can be done in just one place.

How to make your Apache server support SSI

Apache does not support SSI by default, and we need to change httpd.conf to configure it. Here I take Apache on the windows platform as an example, open the httpd.conf file in the conf directory, search for "AddType text/html .shtml", and find:

#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml

Remove the # in front of these two lines, you can use the include syntax of ssi in the page with the suffix name of shtml, if you want to use the include function of ssi in the html/htm page, we need to add the file suffix name to support ssi ,Modify as follows:

AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm

We will see a comment above these two lines:

# (You will also need to add "Includes" to the "Options" directive.)

This means that in addition to modifying these two lines, you also need to add Include to the Options item of your server project configuration directory configuration, in order to use the SSI include function normally.

for example:

I added the following virtual hosts in apache's httpd-vhosts.conf file:

<VirtualHost *:80>
ServerName www.debug.org
DocumentRoot "D:/Project"
DirectoryIndex index.html index.php index.shtml
ErrorLog "logs/eims-error.log"
CustomLog "logs/eims-access.log" combined
<Directory "D:/Project">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>

The host domain name: www.debug.org, the corresponding virtual directory is: D:/Project, then we should locate Options Indexes FollowSymLinks in the virtual host and add the keyword: Includes at the end of the item, that is, after modification:

<VirtualHost *:80>
ServerName www.debug.org
DocumentRoot "D:/Project"
DirectoryIndex index.html index.php index.shtml
ErrorLog "logs/eims-error.log"
CustomLog "logs/eims-access.log" combined
<Directory "D:/Project">
Options Indexes FollowSymLinks Includes
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>

Save httpd.conf and restart apache. At this point, we have completed the settings for Apache SSI.

Complete the SSI configuration so that apache can parse the include syntax of the SSI shtml page. Let's talk about how to use the include command in the next page.

For example, if we want to refer to the header.html page in the include directory in the root directory from index.shtml in the root directory, we can write:

Refer to the header file relative to the current virtual directory:

<!--#include virtual="includes/header.html" -->

<!--#include virtual="/includes/header.html" -->

The path must be written correctly. If the path is incorrect, an error will be reported: [an error occurred while processing this directive]

We can also use the file attribute of include to refer to the file, giving the relative path of the current directory, which cannot use "../", nor absolute path. For example: <!--#include file="header.html" --> This requires that each directory contains a header.html file. (My understanding is that the included file is the same level as the file or the next level directory or the file under the next level directory, such as test.html at the same level, or test/test1.html under the same level directory)

 

 

2. How to configure SSI on nginx
The options required are mainly the following three:
ssi: the default value is off, when ssi is enabled, it is set to on
ssi_silent_errors: the default value is off, after it is turned on, no error message will be output when processing SSI file errors" [an error occurred while processing the directive]".
ssi_types: The default is text/html, so if you need to support html, you don't need to set this sentence, if you need to support shtml, you need to set: ssi_types text/shtml The
three parameters can be placed under the scope of http, server or location.

3. Examples

    1. server {  
    2.     listen  10.3.9.27:80;  
    3.     server_name  www.ball.com;  
    4.     location / {  
    5.         ssi is;  
    6.         ssi_silent_errors on;  
    7.         ssi_types text/shtml;  
    8.         index index.shtml;  
    9.         root /usr/local/web/wwwroot;  
    10.         expires 30d;  
    11.         access_log      /data/logs/www.ball.com-access_log main;  
    12.     }  
    13. }  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324813058&siteId=291194637
ssi