广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >nginx php403错误怎么解决
  • 858
分享到

nginx php403错误怎么解决

nginxphp 2022-11-23 10:11:13 858人浏览 安东尼
摘要

本教程操作环境:linux5.9.8系统、PHP8.1版、Dell G3电脑。nginx php403错误怎么解决?nginx + php 403 原因分析 问题:配置的网站,访问出现报错:Access Denied (403) 常见解决

教程操作环境: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.
; /file/uploads/202211/23/vsijgkaoeen.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错误怎么解决的详细内容,更多请关注编程网其它相关文章!

--结束END--

本文标题: nginx php403错误怎么解决

本文链接: https://www.lsjlt.com/news/173545.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • nginx php403错误怎么解决
    本教程操作环境:linux5.9.8系统、PHP8.1版、Dell G3电脑。nginx php403错误怎么解决?nginx + php 403 原因分析 问题:配置的网站,访问出现报错:Access Denied (403) 常见解决...
    99+
    2022-11-23
    nginx php
  • nginx php403错误如何解决
    今天小编给大家分享一下nginx php403错误如何解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。nginx php4...
    99+
    2023-07-04
  • 【Nginx】解决413错误
    项目场景: 接收Excel文件 问题描述 调用该接口时发生413错误 接口服务nginx日志 2022/09/09 07:02:18 [error] 10#10: *6 client intended to send too large ...
    99+
    2023-08-21
    nginx java 服务器
  • nginx不提示php错误怎么解决
    在日常的网站开发中,我们经常会使用Nginx作为Web服务器,并配合PHP作为后端语言。然而有时候我们会发现,即使PHP中存在错误,Nginx也不会提示任何信息,这让我们调试程序非常困难。本文将介绍一些解决方法,使Nginx能够提示PHP错...
    99+
    2023-05-14
    php nginx
  • nginx报405 not allowed错误怎么解决
    当nginx返回"405 not allowed"错误时,表示HTTP方法不被服务器支持。这可能是由于以下几个原因引起的: 请求...
    99+
    2023-10-25
    nginx
  • nginx 504 Gateway Time-out错误怎么解决
    Nginx 504 Gateway Time-out错误通常表示服务器在代理请求到上游服务器时等待回应的时间超过了预设的时间。下面是...
    99+
    2023-08-15
    nginx
  • Nginx php怎样解决502 Bad Gateway错误
    这期内容当中小编将会给大家带来有关Nginx php怎样解决502 Bad Gateway错误,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。在Web服务器中有很多先进的技...
    99+
    2022-10-19
  • 解决nginx“504 Gateway Time-out”错误
    做网站的同学经常会发现一些nginx服务器访问时候提示504 Gateway Time-out错误,一般情况下是由nginx默认的fastcgi进程响应慢引起的,但也有其他情况,这里...
    99+
    2022-11-12
  • 解决nginx“504 Gateway Time-out”错误
    在解决Nginx "504 Gateway Time-out"错误时,可以尝试以下几种方法:1. 增加proxy_read_time...
    99+
    2023-08-14
    nginx
  • Nginx的405notallowed错误解决方法
    目录1、问题情况2、问题原因3、问题解决4、拓展1、问题情况 首先看到的页面是nginx返回的页面,得知错误要从nginx上来解决 <html> <head>...
    99+
    2023-05-19
    405 not allowed Nginx 405 not allowed
  • Nginx的405 not allowed错误解决
    1、问题情况 首先看到的页面是nginx返回的页面,得知错误要从nginx上来解决 405 Not Allowed405 Not Allowednginx/1.0.11 2、问题原因 因为这里请求的静态文件采用的是post方法,n...
    99+
    2023-08-30
    nginx 服务器 运维 405 not allowed 405 转态
  • nginx php报502错误是什么原因?怎么解决?
    在使用Nginx+PHP开发Web应用时,经常会出现502错误。出现502网关错误可能会导致一系列的问题,让开发者束手无策。本文通过对这种错误进行探讨,帮助读者了解502错误的原因,并提供解决方案来解决这个问题。一、什么是502错误?简而言...
    99+
    2023-05-14
    502错误 nginx php
  • 解决 nginx 启动错误 nginx: [emerg] host not found in upstream
    感谢这个朋友简单而清晰的解决办法。 在配置nginx支持PHP的时候,因为之前有站点,配置的比较乱。尤其是支持JSP 导致重启nginx时,一直报错 nginx: [emerg] host not found in upstream 类似这...
    99+
    2023-08-31
    nginx 运维 php
  • nginx常见502错误的解决方法
    Nginx 502错误情况1: 网站的访问量大,而php-cgi的进程数偏少。 针对这种情况的502错误,只需增加php-cgi的进程数。具体就是修改/usr/local/php/etc/php-fpm.con...
    99+
    2023-09-09
    nginx 服务器 php Powered by 金山文档
  • Nginx出现502错误的解决方案
    本篇内容介绍了“Nginx出现502错误的解决方案”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!方法一:在...
    99+
    2022-10-19
  • 如何解决nginx“504 Gateway Time-out”错误
    这篇文章主要介绍“如何解决nginx“504 Gateway Time-out”错误”,在日常操作中,相信很多人在如何解决nginx“504 Gateway Time-out”错误问题上存在疑惑,小编...
    99+
    2023-06-22
  • nginx不提示php错误如何解决
    本篇内容主要讲解“nginx不提示php错误如何解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“nginx不提示php错误如何解决”吧!一、理解错误报告及搜集方法在部署服务器的过程中,我们习惯...
    99+
    2023-07-05
  • Nginx报404错误的详细解决方法
    近日在部署项目时,出现了一些问题,如图 正常的登录界面是可以访问的,但是在登录之后访问之后的地址会报404错误,于是去查看是否配置有错误,但是查看之后发现,nginx.conf与c...
    99+
    2022-11-13
  • 怎么解决oracle错误
    这篇文章主要讲解了“怎么解决oracle错误”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么解决oracle错误”吧!myibts 文件传参:前台传Map 参数。<...
    99+
    2023-05-31
  • java.exe错误怎么解决
    本篇内容介绍了“java.exe错误怎么解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!序言----------------------大...
    99+
    2023-06-03
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作