SSI 包括不使用 Apache 在 Debian 上工作

Mik*_*ike 12 debian server-side-includes apache-2.2

我试图让 SSI 在运行 Apache 的 Debian 上工作,但是.shtml文件没有被解析。从 PHP 文件中,phpinfo()我可以看到加载的模块部分显示以下内容:

mod_mime_xattr mod_mime mod_mime_magic
Run Code Online (Sandbox Code Playgroud)

/etc/apache2/mods-enabled/mime.conf我有(除其他外):

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Run Code Online (Sandbox Code Playgroud)

/etc/apache2/sites-enabled/domain.com.conf(对于有问题的虚拟主机)我有:

<Directory /home/username/public_html>
Options +Includes
allow from all
AllowOverride All 
</Directory>
Run Code Online (Sandbox Code Playgroud)

为了更好地衡量,我还添加了以下内容:

<Directory />
Options +Includes
</directory>
Run Code Online (Sandbox Code Playgroud)

在用户的.htaccess文件中,我尝试添加:

Options +Includes
AddType text/html shtml
AddHandler server-parsed shtml
Run Code Online (Sandbox Code Playgroud)

似乎没有任何效果。我怎么能调试呢?

编辑:

这是输出,ls /etc/apache2/mods-enabled/以防万一

actions.conf          dav_svn.load         proxy_balancer.load
actions.load          deflate.conf         proxy.conf
alias.conf            deflate.load         proxy_connect.load
alias.load            dir.conf             proxy_http.load
auth_basic.load       dir.load             proxy.load
auth_digest.load      env.load             python.load
authn_file.load       fcgid.conf           reqtimeout.conf
authz_default.load    fcgid.load           reqtimeout.load
authz_groupfile.load  mime.conf            rewrite.load
authz_host.load       mime.load            ruby.load
authz_user.load       mime_magic.conf      setenvif.conf
autoindex.conf        mime_magic.load      setenvif.load
autoindex.load        mime-xattr.load      ssl.conf
cgi.load              negotiation.conf     ssl.load
dav_fs.conf           negotiation.load     status.conf
dav_fs.load           php5.conf            status.load
dav.load              php5.load            suexec.load
dav_svn.conf          proxy_balancer.conf
Run Code Online (Sandbox Code Playgroud)

Mik*_*ike 12

为了让服务器端包含工作,include模块也需要被加载。您可以通过以 root 身份执行以下命令来完成此操作:

a2enmod include
Run Code Online (Sandbox Code Playgroud)

或者执行以下命令:

ln -s /etc/apache2/mods-available/include.conf /etc/apache2/mods-enabled/include.conf
ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled/include.load
Run Code Online (Sandbox Code Playgroud)

然后重启apache。

请注意,如果您将 SSI 添加到您的.shtml文件中,.htaccess您将执行AddOutputFilter INCLUDES .shtml. 或者替换.shtml您想要由服务器端解析的任何文件类型包含。

当前的 Debian 配置文件/etc/apache2/mods-available/mime.conf包含一个错误,因为它添加了以下内容:

<IfModule mod_mime.c>
[...]
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
[...]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

无需先检查是否mod_include.c已加载。要解决此问题,您可以将这些行更改为:

<IfModule mod_mime.c>
[...]
<IfModule mod_include.c>
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
[...]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

<IfModule>标签可以被嵌套。这将消除您在mod_include.c未加载的情况下遇到的错误消息。