您现在的位置是:群英 > 开发技术 > PHP语言
nginx php403原因是什么,常见解决方法有哪些
Admin发表于 2022-11-30 17:46:521188 次浏览
这篇文章给大家介绍了“nginx php403原因是什么,常见解决方法有哪些”的相关知识,讲解详细,步骤过程清晰,对大家进一步学习和理解“nginx php403原因是什么,常见解决方法有哪些”有一定的帮助,希望大家阅读完这篇文章能有所收获。下面就请大家跟着小编的思路一起来学习一下吧。

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

本教程操作环境:linux5.9.8系统、PHP8.1版、Dell G3电脑。

nginx php403错误怎么解决?

nginx + php 403 原因分析

问题:

配置的网站,访问出现报错:Access Denied (403)

常见解决方法:

1、文件权限问题

可能是文件权限问题,没有读权限。

或者selinux没有关闭。

2、security.limit_extensions

查看nginx的错误日志error.log,发现有如下错误:

2016/07/07 10:20:13 [error] 17710#0: *2145 FastCGI sent in stderr: "Access to the script '/home/www/game/10313156.html' has been denied (see security.limi
t_extensions)" while reading response header from......
登录后复制

从5.3.9开始,php官方加入了一个配置"security.limit_extensions",默认只允许执行扩展名为".php"的文件,造成了其他类型的文件不支持的问题。

官方说明 :

; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5
登录后复制

修改php-fpm.conf:(加入需要的文件扩展名)

security.limit_extensions = .php .html .js .css .jpg .jpeg .gif .png .htm
登录后复制

3、cgi.fix_pathinfo

通过这种url访问,显示Acess denied 错误。

nginx错误日志:

2016/07/08 09:47:12 [error] 24297#0: *3348 FastCGI sent in stderr: "Access to the script '/home/www/home.php/game/qr' has been denied (see security.limit_extensions)" while reading response header......
登录后复制

修改php.ini :(cgi.fix_pathinfo 默认为1 )

cgi.fix_pathinfo = 1
登录后复制

官方说明 :

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
登录后复制

其实cgi.fix_pathinfo = 1 会引发文件类型错误解析漏洞,建议是设置 cgi.fix_pathinfo = 0 。

( 关于漏洞的理解:

  当cgi.fix_pathinfo=1时,访问路径:/foo.jpg/file.php ,如果file.php文件不存在,则php解析器会试图猜测你要执行哪个文件,沿着路径往回找。如果foo.jpg存在, 并且包含php代码,php解析器就会去执行foo.jpg 。

  当cgi.fix_pathinfo=0时,PHP 解释器仅尝试给出的路径,如果文件没有找到就停止处理。

)

但将 cgi.fix_pathinfo = 0 ,可能会导致很多MVC框架(如ThinkPHP)无法正常运行。

4、

在php.ini上设置了:open_basedir=/home:/tmp/:/proc/

重启php-fpm

访问网页,按ctrl + F5频繁刷新的时候,会报 Access Denied错误。Access Denied是偶尔才会出现,不是一直403 。

nginx错误日志记录:

2016/07/09 08:32:40 [error] 26954#0: *2127721 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: open_basedir restriction in effect. File(/home/www/touch/web/index.php) is not within the allowed path(s): (/home/wwwroot:/tmp/:/proc/) in Unknown on line 0
PHP message: PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0
Unable to open primary script: /home/www/touch/web/index.php (Permission denied)" while reading response header from upstream, client: 117.136.1.22, server: test.hjq.com, request: "GET /index.php?c=Zs&a=getcontent HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.hjq.com"
登录后复制

2、In your nginx config file set fastcgi_pass to your socket address (e.g. unix:/var/run/php-fpm/php-fpm.sock;) instead of your server address and port.
3、Check your SCRIPT_FILENAME fastcgi param and set it according to the location of your files.
4、In your nginx config file include fastcgi_split_path_info ^(.+\.php)(/.+)$; in the location block where all the other fastcgi params are defined.

以上就是关于“nginx php403原因是什么,常见解决方法有哪些”的介绍了,感谢各位的阅读,希望文本对大家有所帮助。如果想要了解更多知识,欢迎关注群英网络,小编每天都会为大家更新不同的知识。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

标签: nginx php403
相关信息推荐
2022-09-16 17:55:40 
摘要:两种只读的方法:1、使用attr()给复选框添加disabled属性,语法“$("input[type='checkbox']").attr("disabled",true);”;2、使用click()设置复选框点击时不进行checkbox状态改变,语法“$("input[type='checkbox']").click(function(){return false;})”。
2022-06-16 09:25:44 
摘要:php预定义数组有9个:1、“$_SERVER”,是一个包含诸如头信息、路径和脚本位置的数组;2、“$_GET”,是通过GET方法传递的变量组成的数组;3、“$_POST”,是通过POST方法传递的变量组成的数组;4、“$_FILES”等。
2022-07-30 17:24:21 
摘要:vue可以用的框架:1、Ant Design Vue,是一个非常成熟的框架,使用它创建用户界面非常简单;2、BalmUI,是一款交互体验非常优秀的UI组件库;3、Wave UI,是一个响应式,可访问且易于触摸的UI组件框架;4、Vuestic,提供了50多个具有独特功能和广泛可配置性的组件;5、Element,是一个桌面端组件库;6、Quasar,是一个以性能为中心的框架。
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部