在 Apache 中完整开启 .shtml (SSI) 解析

1. 启用必要模块

SSI 需要 mod_include,而执行命令(#exec)通常需要 mod_cgi

bash 复制代码
sudo a2enmod include
sudo a2enmod cgi

2. 修改站点配置文件

编辑你的虚拟主机文件(如 /etc/apache2/sites-available/000-default.conf),在 <Directory> 段落中添加关键指令。

核心配置如下:

apache 复制代码
<Directory /var/www/html>
    # 1. 必须包含 Includes 和 ExecCGI
    Options +Indexes +FollowSymLinks +Includes +ExecCGI
    
    # 2. 允许读取 .shtml 扩展名
    AddType text/html .shtml
    
    # 3. 设置输出过滤器,让 Apache 解析文件中的 SSI 标签
    AddOutputFilter INCLUDES .shtml
    
    # (可选) 设置默认首页包含 index.shtml
    DirectoryIndex index.shtml index.html
    
    AllowOverride All
    Require all granted
</Directory>

3. 设置全局安全策略 (可选)

有时 include.conf 中的全局设置会限制 exec。检查 /etc/apache2/mods-available/include.conf

apache 复制代码
<IfModule mod_include.c>
    # 确保没有使用 IncludesNoExec
    # XBitHack 允许通过文件的"可执行"权限位来控制 SSI 行为
    XBitHack full
</IfModule>

4. 重启服务并测试

每次修改配置后必须重启:

bash 复制代码
sudo systemctl restart apache2
相关推荐
D愿你归来仍是少年7 小时前
Apache Spark 第 9 章:Spark 性能调优
大数据·spark·apache
Hello.Reader10 小时前
Apache Arrow 在 PySpark 中的使用提速 Pandas 转换与 UDF 的关键武器
apache·pandas
言之。12 小时前
Apache ZooKeeper 核心技术全解(面试+实战版)
zookeeper·面试·apache
AI架构师之家1 天前
Apache Camel使用教程一
apache
yzx9910131 天前
实时数据处理实战:使用 Apache Flink 消费 Kafka 数据并进行窗口聚合
flink·kafka·apache
Shepherd06192 天前
【IT 实战】Apache 反向代理 UniFi Controller 的终极指北(解决白屏、502、400 错误)
运维·网络·apache·it·unifi
额1292 天前
CentOS 7 安装apache部署discuz导入数据库表
数据库·centos·apache
qzhqbb2 天前
Nginx/Apache 访问规则
运维·nginx·apache
HashData酷克数据3 天前
# Apache Cloudberry 2.1.0 版本前瞻:内核、PXF 与备份生态持续演进
apache
D愿你归来仍是少年3 天前
Apache Spark 第 8 章:Structured Streaming 流处理
大数据·spark·apache