NGINX在HTML文件中执行嵌入式PHP [英] NGINX execute embedded PHP in HTML file

查看:408
本文介绍了NGINX在HTML文件中执行嵌入式PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下配置:

server {
  listen 80 default_server;

  access_log /var/www/logs/access.log;                                                                                           
  error_log /var/www/logs/error.log error;     

  root /var/www/web/;

  index index.html index.php;

  server_name _;

  location / { 
    try_files $uri $uri/ =404;
  }

  # HACK: This is temporary to work around renaming dozens of HTML links
  location ~ \.htm$ {
    root html;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.htm;

    include fastcgi_params;
  }
  # HACK: This is temporary to work around renaming dozens of HTML links

  location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
      return 404;
    }

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;

    include fastcgi_params;
  }
}

然后我更新了/etc/php5/fpm/pool.d/www.conf并添加了以下行:

And I updated /etc/php5/fpm/pool.d/www.conf adding the line:

security.limit_extensions = .php .html 

重新启动FPM和NGINX,但是当我访问.html文件时,PHP无法呈现... *.php文件将按预期执行...

Restarted FPM and NGINX but when I access .html files the PHP is not rendered...*.php files execute as expected...

我还想念什么?

推荐答案

我将其删除:

    # HACK: This is temporary to work around renaming dozens of HTML links
  location ~ \.htm$ {
    root html;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.htm;

    include fastcgi_params;
  }

并改用它:

location ~ \.(php|html|htm)$ {
   root           html;
   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_index  index.html;
   fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include        fastcgi_params;
}

我希望这能解决您的问题.

I hope this solves your issue.

这篇关于NGINX在HTML文件中执行嵌入式PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆