Nginx 配置 SSI 的方法
SSI 簡介
SSI:Server Side Include,是一種基於服務端的網頁製作技術,在頁面內容發送到客戶端之前,使用SSI指令將文本、圖片或代碼信息包含到網頁中。對於在多個文件中重複出現內容,使用SSI是一種簡便的方法,將內容存入一個包含文件中即可,不必將其輸入所有文件。通過一個非常簡單的語句即可調用包含文件,此語句指示 Web 服務器將內容插入適當網頁。而且,使用包含文件時,對內容的所有更改只需在一個地方就能完成。
修改 Nginx 配置文件
- 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
Nginx.conf 實例
server {
listen 80;
server_name admin-demo.laputateam.com;
root /home/wwwroot/Laputa_admin_demo;
index index.html index.htm index.php;
location ~.*\.php?$ {
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
HTML 頁面包含其他頁面實例
<!DOCTYPE html>
<html>
<!--#include file="moudle_header.html"-->
<body>
<!--#include file="moudle_navbar.html"-->
<!--#include file="moudle_sidebar.html"-->
<div class="main">
<!-- 內容主體區域 -->
</div>
<!--#include file="moudle_footer.html"-->
</body>
</html>