SSI简介 与 nginx开启SSI

Server Side Include : 服务器端嵌入

原理 : 将内容发送到浏览器之前,可以使用“服务器端包含 (SSI)”指令将文本、图形或应用程序信息包含到网页中。因为包含 SSI 指令的文件要求特殊处理,所以必须为所有 SSI 文件赋予 SSI文件扩展名。默认扩展名是 .stm、.shtm 和 .shtml

主要有以下几种用用途:

1、显示服务器端环境变量<#echo>

2、将文本内容直接插入到文档中<#include>

3、显示WEB文档相关信息<#flastmod #fsize> (如文件制作日期/大小等)

4、直接执行服务器上的各种程序<#exec>(如CGI或其他可执行程序)

5、设置SSI信息显示格式<#config>;(如文件制作日期/大小显示方式) 高级SSI<XSSI>;可设置变量使用if条件语句。

nginx 开启 SSI

编辑nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

加入如下代码

ssi on;

ssi_silent_errors on;

ssi_types text/shtml;

保存 重启 nginx

本人配置案例

location ~ \.shtml$ {
                ssi on;
                ssi_silent_errors on;
                ssi_types text/shtml;
        }

应用到SSI的地方是 为各个游戏官网分离静态碎片,采用SSI的方式引入进去

<!--#include file="head.shtml"-->

其中遇到的挫折有

file的路径名 写成了访问地址 例如 <!--#include file="http://hejungw.feiliu.com/site/gc/wap/list/head.shtml"--> 这是不对的

后又写成服务器端绝对地址 例如 <!--#include file="/data0/www/html/hejungw/static/ssi/13/head.shtml"--> 这也是不对的

最后写成了 相对地址 方正确。

include 另外一种写法

<!--#include virtual="/site/gc/wap/list/head.shtml"-->

Virtual:给出到服务器端某个文档的虚拟路径

虚拟路径即为访问该片段的url去掉 域名 剩下的路径

本项目中访问 head片段 的url 为 http://hejungw.feiliu.com/site/gc/wap/list/head.shtml

综上 若要引入外部文件 用 include virtual 比较方便