在 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
相关推荐
DolphinScheduler社区14 分钟前
Apache DolphinScheduler 与 Spring Cloud Data Flow:差异与优势解析
spring·spring cloud·apache·海豚调度·大数据工作流调度
SeaTunnel6 小时前
Apache SeaTunnel 4 月有何新动作?连接器增强与 Zeta 稳定性提升等亮点速览
大数据·数据仓库·spark·apache·seatunnel
℡終嚸♂6802 天前
Apache Tomcat CVE-2025-55752 CTF Writeup
tomcat·apache·firefox
27669582922 天前
某白山小程序限制PC端调试
python·小程序·apache·小程序逆向·某白山·限制pc调试
杰建云1672 天前
商家小程序怎么做?
大数据·apache·小程序制作
小冷爱学习!3 天前
Apache Shiro 1.2.4 反序列化漏洞Shiro-550(CVE-2016-4437)
服务器·网络·python·安全·网络安全·apache
有趣灵魂3 天前
Java Spring Boot根据Word模板和动态数据生成Word文件
java·spring boot·word·apache
phltxy3 天前
分布式链路追踪实战:Apache SkyWalking 从入门到精通
分布式·apache·skywalking
大厂数码评测员5 天前
免费菜谱管理小程序怎么做才顺手:从情侣、个人、家庭三类场景拆需求和实现
服务器·小程序·apache