# 在 httpd.conf 或虛擬主機配置中添加
AddType application/x-httpd-php .html .htm
# 或僅針對特定目錄
<Directory "/var/www/html">
AddHandler application/x-httpd-php .html .htm
</Directory>
# 根目錄 .htaccess AddHandler application/x-httpd-php .html .htm # PHP 7+ 部分環境需用 AddHandler application/x-httpd-php7 .html .htm
編輯站點配置 /etc/nginx/sites-enabled/your_site.conf:
location ~ \.(html|htm)$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 或 127.0.0.1:9000
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# 可選:禁用緩存確保即時生效
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
重載配置:nginx -t && systemctl reload nginx
,輕量級片段復用。