【问题标题】:PHP include in .HTML file not getting parsedPHP包含在.HTML文件中没有被解析
【发布时间】:2021-07-05 15:38:12
【问题描述】:

从 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*'

【问题讨论】:

  • 所以你把php代码放在.html文件里?
  • 它可能正确包含它,但没有处理它,因为“父”页面是 .html,而不是 .php。
  • 你能发布你的 nginx 配置吗?你在使用 php-fpm 吗?假设您是,您可以调整 security.limit_extensions 中定义的扩展名以包含 .html
  • @forloops nginx conf 已上传。
  • @droopsnoot 这在旧的 Apache 服务器上运行良好。迁移到 Nginx 后停止工作

标签: php html nginx server-side-rendering ssi


【解决方案1】:

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

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

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

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

security.limit_extensions = .php .html 

【讨论】:

  • 除了 nginx 还需要启动其他服务器吗?
  • 用上面的内容更新了“ /etc/nginx/sites-available/mysite.com.conf ”,重新启动了服务器,但仍然是同样的问题。将“security.limit_extensions = .php .html”添加到/etc/php/7.4/fpm/php-fpm.conf 然后重新启动服务器,但仍然没有运气!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 2011-05-20
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多