1. 程式人生 > >debian系統下apache2開啟ssi功能

debian系統下apache2開啟ssi功能

SSI (Server Side Include)的 html 副檔名 (.shtml), 通常稱為"伺服器端嵌入"或者叫"伺服器端包含"
說白了就是類似其他語言如 PHP include 引入其他檔案,SSI 是通過配置伺服器,一個靜態 html 檔案引入另一個 html 檔案的功能

被包含檔案與父檔案存在於相同目錄中
<!-- #include file = "index.html" -->
被包含檔案位於指令碼虛擬目錄中
<!-- #include virtual = "/scripts/tools/index.html" -->

1.載入mod_include.so模組

建立符號連結
sudo ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled
或者直接拷貝
cp /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled/include.load


2.開啟剛剛建立好的軟連線配置檔案
sudo vi /etc/apache2/mods-enabled/include.load

新增以下內容

# Depends: mime
LoadModule include_module /usr/lib/apache2/modules/mod_include.so

# 上面內容是已有的,新增下面內容
<Directory /var/www/html/>
Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
AddType text/html .shtml .html #這兩個是主要的配置檔案
AddOutputFilter INCLUDES .shtml .html #加上 .html 意思是可以 include .html 檔案
</Directory>


3.重啟apache2
啟動:service apache2 start 
重啟:service apache2 restart
停止:service apache2 stop

4.測試

1.html

<html>
<body>
<!--#include file="2.html"-->
</body>
</html>


2.html
<h1>Hello World!</h1>

瀏覽器執行 1.html 成功顯示 Hello World! 說明配置成功

 

done!