zoukankan      html  css  js  c++  java
  • ssi,服务器端包含,<include file="">

    一、什么是SSI

    ssi,全称Server Side Include,中文名,服务器端包含。

    SSI (Server Side Includes)是HTML页面中的指令,在页面被提供时由服务器进行运算,以对现有HTML页面增加动态生成的内容,而无须通过CGI程序提供其整个页面,或者使用其他动态技术。

    对什么时候用SSI,而什么时候用某些程序生成整个页面的权衡,取决于页面中有多少内容是静态,有多少内容需要在每次页面被提供时重新计算。SSI是一种增加小段信息的好方法,诸如当前时间。如果你的页面大部分是在被提供时生成的,那就要另找方案了。

    二、apache配置SSI

    需要开启1、 include_module模块,但需要注意关闭如虚拟服务 http-vhost模块(请大神指教两个模块的联调),

    1 LoadModule include_module modules/mod_include.so

    2、Options 添加includes

       #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.4/mod/core.html#options
        # for more information.
        #
        Options Indexes FollowSymLinks Includes

     

    文件后缀一般为.shtml测试代码

    1                  <!--#include file="aa.html"--><br/>
    2         Today is <!--#echo var="DATE_LOCAL" --><br/>
    3        修改时间配置<!--#config timefmt="%A %B %d, %Y" --><br/>
    4          Today is<!--#echo var="DATE_LOCAL" --><br/>

    输出为

    3、若需要指定其他后缀 如.html,可修改 http.conf,  添加后缀名

    1     #
    2     # Filters allow you to process content before it is sent to the client.
    3     #
    4     # To parse .shtml files for server-side includes (SSI):
    5     # (You will also need to add "Includes" to the "Options" directive.)
    6     #
    7     AddType text/html .shtml .html
    8     AddOutputFilter INCLUDES .shtml .html

     三、用途

    1.显示服务器端环境变量<#echo>
    2.将文本内容直接插入到文档中<#include>
    3.显示WEB文档相关信息<#flastmod #fsize> (如文件制作日期/大小等)
    4.直接执行服务器上的各种程序<#exec>(如CGI或其他可执行程序)
    5.设置SSI信息显示格式<#config>(如文件制作日期/大小显示方式) 高级SSI<XSSI>可设置变量使用if条件语句。
     
    其中 2,是最常用的。
    示例  
    <!--被包含文件与父文件存在于相同目录中。 -->  
    <!-- #include file = "myfile.inc" -->  

    <!--被包含文件位于脚本虚拟目录中。 -->  
    <!-- #include virtual = "/scripts/tools/global.inc" -->  
     
    1 <!--#include file="top.html"-->
    2 <div>
    3     这是main,正文内容
    4 </div>
    5 <!--#include file="foot.html"-->

     虽然有包含代码,但http请中只请求了 index.html,所以得出文件的包含是在服务器中就完成了!

    http://man.chinaunix.net/newsoft/ApacheManual/howto/ssi.html

  • 相关阅读:
    n皇后问题
    几种NFS系统对比,选型理由
    MooseFs集群故障恢复运维
    TB级NFS数据平滑迁移方案设计与实现
    NFS挂载各机显示用户不同的问题
    TB级NFS数据平滑迁移系列
    mysql备份和恢复
    Java基础赋值符号
    java 流程控制基础之if else
    Java基础赋值符号
  • 原文地址:https://www.cnblogs.com/blog-index/p/6842286.html
Copyright © 2011-2022 走看看