-★出爺;3 发表于 2018-11-13 08:07:50

Nginx下html文件嵌入php语句,php内容无法正常解析

  问题:
  在nginx中html文件嵌入了php语句,造成无法访问以及访问html文件只显示html标签内容而不输出php部分内容.
  配置过程:
  nginx配置server,站点下有一个c.html,文件内容如下
  hello html
  
  访问c.html文件时,只显示标签内的内容.而没有显示出php语句中的echo.

  在nginx配置文件server下加入html文件交给本地php-fpm处理解析
  location ~ .*\.html$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  include      fastcgi_cgi;
  }
  再次访问c.html文件时,前台页面显示

  解决思路:
  查看nginx日志文件 error.log
  发现有报错内容为:
  2014/04/16 09:53:43 10626#0: *274 FastCGI sent in stderr: "Access to the script '/home/web/test.zrer.com/c.html'
  has been denied (see security.limit_extensions)" while reading response header from upstream, client: 116.226.237.182,
  server: test.zrer.com, request: "GET /c.html HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.zrer.com"
  查看php-fpm文件

  发现是php配置问题,在php-fpm配置文件内有see security.limit_extensions这项,默认只允许解析扩展名为.php的文件,造成其他文件不可解析.
  解决办法:
  修改php-fpm文件, 去掉;security.limit_extensions = .php .php3 .php4 .php5前面的注释号,在最后添加.html类型文件

  重启php-fpm 服务
  # killall php-fpm
  #/usr/local/lnmp/php/sbin/php-fpm
  再次访问c.html

  问题解决.

页: [1]
查看完整版本: Nginx下html文件嵌入php语句,php内容无法正常解析