nginx配置ssi

一、什么是SSI

SSI:Server Side Include,是一种基于服务端的网页制作技术,大多数(尤其是基于Unix平台)的web服务器如Netscape Enterprise Server等均支持SSI命令。

它的工作原因是:在页面内容发送到客户端之前,使用SSI指令将文本、图片或代码信息包含到网页中。对于在多个文件中重复出现内容,使用SSI是一种简便的方法,将内容存入一个包含文件中即可,不必将其输入所有文件。通过一个非常简单的语句即可调用包含文件,此语句指示 Web 服务器将内容插入适当网页。而且,使用包含文件时,对内容的所有更改只需在一个地方就能完成。

二、如何在nginx上配置SSI

需要的选项主要是以下三个:

ssi: 默认值off,启用ssi时将其设为on
ssi_silent_errors: 默认值off,开启后在处理SSI文件出错时不输出错误提示"[an error occurred while processing the directive]"。
ssi_types: 默认是text/html,所以如果需支持html,则不需要设置这句,如果需要支持shtml则需要设置:ssi_types text/shtml

三个参数可以放在http, server或location作用域下。

三、配置用例

server {
        listen       80;
        server_name  www.fn.com;

        access_log   /var/log/nginx/www.fn.log  main;
        root  /home/www.fn.com/public; 
        index  index.html index.htm index.php;

        location / {
             ssi on;
                ssi_silent_errors on;
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ .php {
                root  /home/www.fn.com/public;
                fastcgi_index  index.php;
                fastcgi_pass   unix:/tmp/php-cgi.sock;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}
原文地址:https://www.cnblogs.com/cyleon/p/11011112.html