天天看點

網站頁面出現:an error occurred while processing the directive

今天搭建網站時候通路首頁出現報錯,本來以為是我php-fpm沒裝好,後來發現是Nginx ssi配置問題。

首頁報錯:an error occurred while processing the directive

naginx日志報錯:

2014/03/28 17:26:06 [error] 24835#0: *8 invalid SSI command: "導航下拉效果begin" while sending to client, client: X.X.X.X, server: beta.X.cn, request: "GET /index.php?c=content&a=list&catid=7 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "beta.X.cn", referrer: "http://beta.X.cn/index.php?c=content&a=list&catid=6"

#########################

解決辦法,轉載

一:為什麼用ssi?

一個登入使用者在頁面通路的時候如何充分利用 cache?

頁面靜态化的一個大問題是登入使用者通路頁面如何靜态化。 例如首頁, 大部分的頁面内容需要緩存但是使用者登入後的個人資訊是動态資訊, 不能緩存。 那麼如何解決這個"頁面部分緩存"問題?

現有的方案是利用 SSI - Server Side include.

Nginx SSI 實作是 http://wiki.nginx.org/NginxHttpSsiModule

這裡最關鍵的就是靜态檔案可以包含一個動态的網頁的 URL.

二:配置ssi

主要是三個參數,ssi,ssi_silent_errors和ssi_types,均可以放在http,server和location的作用域下。

ssi on

開啟ssi支援,預設是off

ssi_silent_errors on

預設值是off,開啟後在處理SSI檔案出錯時不輸出錯誤提示:"[an error occurred while processing the directive] "

ssi_types

預設是ssi_types text/html,是以如果需要htm和html支援,則不需要設定這句,如果需要shtml支援,則需要設定:ssi_types text/shtml

SSI的格式:

< !--#include file="bottom.htm"-->

< !--#include virtual="/hx/bottom.htm"-->

路徑是相對server中root根目錄。

更多請參見官方文檔:http://wiki.nginx.org/NginxChsHttpSsiModule

示例:

1.開啟shtml字尾的檔案名支援ssi

server{

   ......

   ssi on;

   ssi_silent_errors on;

   ssi_types text/shtml;

}

2.開啟html字尾的檔案名支援ssi

3.在zt目錄下開啟html字尾的檔案名支援ssi

   location /hx/{

       ssi on;

       ssi_silent_errors on;

   }