ITPub博客

首页 > IT职业 > IT生活 > Nginx下html文件嵌入php语句

Nginx下html文件嵌入php语句

IT生活 作者:supersea 时间:2021-09-09 09:18:51 0 删除 编辑

问题:

在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_index  index.php;

        include        fastcgi_cgi;

                }

再次访问c.html文件时,前台页面显示 

图片描述

 

 

解决思路:

查看nginx日志文件 error.log

发现有报错内容为:

2014/04/16 09:53:43 [error] 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 服务

[root@localhost ~]# killall php-fpm

[root@localhost ~]#  /usr/local/lnmp/php/sbin/php-fpm

 

再次访问c.html

图片描述

 

问题解决.


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2650/viewspace-2802072/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    90
  • 访问量
    799