PHP 包含在 .HTML 文件中没有被解析

问题描述

从 Apache (Godaddy) 迁移到 Nginx (DigitalOcean),index.html 下面的 PHP 代码不起作用,结果,站点的页脚部分消失了。它在旧服务器上运行良好。

<? include("includes/copyright.PHP") ?>

服务器详情:

Ubuntu 20.04
PHP 7.14.15
Nginx 1.18.0

sudo systemctl list-units 'PHP*'

enter image description here

/etc/nginx/mysite.com.conf

enter image description here

解决方法

在您的 nginx 配置中,更新以 location ~ \.php(/|$) { 开头的行:

location ~ \.(php|html|htm)$ {

然后重启服务。这将允许您的 html 文件通过 php 解析

如果传递给 fastcgi 不起作用,您可以在 php-fpm 配置中添加一个指令:

security.limit_extensions = .php .html