nginxphp403錯(cuò)誤如何解決

今天小編給大家分享一下nginx php403錯(cuò)誤如何解決的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來(lái)了解一下吧。

創(chuàng)新互聯(lián)建站專(zhuān)業(yè)成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè),集網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、網(wǎng)站制作于一體,網(wǎng)站seo、網(wǎng)站優(yōu)化、網(wǎng)站營(yíng)銷(xiāo)、軟文推廣等專(zhuān)業(yè)人才根據(jù)搜索規(guī)律編程設(shè)計(jì),讓網(wǎng)站在運(yùn)行后,在搜索中有好的表現(xiàn),專(zhuān)業(yè)設(shè)計(jì)制作為您帶來(lái)效益的網(wǎng)站!讓網(wǎng)站建設(shè)為您創(chuàng)造效益。

nginx php403錯(cuò)誤的解決辦法:1、修改文件權(quán)限或開(kāi)啟selinux;2、修改php-fpm.conf,加入需要的文件擴(kuò)展名;3、修改php.ini內(nèi)容為“cgi.fix_pathinfo = 0”;4、重啟php-fpm即可。

nginx + php 403 原因分析

問(wèn)題:

配置的網(wǎng)站,訪(fǎng)問(wèn)出現(xiàn)報(bào)錯(cuò):Access Denied (403)

常見(jiàn)解決方法:

1、文件權(quán)限問(wèn)題

可能是文件權(quán)限問(wèn)題,沒(méi)有讀權(quán)限。

或者selinux沒(méi)有關(guān)閉。

2、security.limit_extensions

查看nginx的錯(cuò)誤日志error.log,發(fā)現(xiàn)有如下錯(cuò)誤:

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開(kāi)始,php官方加入了一個(gè)配置"security.limit_extensions",默認(rèn)只允許執(zhí)行擴(kuò)展名為".php"的文件,造成了其他類(lèi)型的文件不支持的問(wèn)題。

官方說(shuō)明 :

; 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:(加入需要的文件擴(kuò)展名)

security.limit_extensions = .php .html .js .css .jpg .jpeg .gif .png .htm

3、cgi.fix_pathinfo

通過(guò)這種url訪(fǎng)問(wèn),顯示Acess denied 錯(cuò)誤。

nginx錯(cuò)誤日志:

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 默認(rèn)為1 )

cgi.fix_pathinfo = 1

官方說(shuō)明 :

; 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

其實(shí)cgi.fix_pathinfo = 1 會(huì)引發(fā)文件類(lèi)型錯(cuò)誤解析漏洞,建議是設(shè)置 cgi.fix_pathinfo = 0 。

( 關(guān)于漏洞的理解:

當(dāng)cgi.fix_pathinfo=1時(shí),訪(fǎng)問(wèn)路徑:/foo.jpg/file.php ,如果file.php文件不存在,則php解析器會(huì)試圖猜測(cè)你要執(zhí)行哪個(gè)文件,沿著路徑往回找。如果foo.jpg存在, 并且包含php代碼,php解析器就會(huì)去執(zhí)行foo.jpg 。

當(dāng)cgi.fix_pathinfo=0時(shí),PHP 解釋器僅嘗試給出的路徑,如果文件沒(méi)有找到就停止處理。

)

但將 cgi.fix_pathinfo = 0 ,可能會(huì)導(dǎo)致很多MVC框架(如ThinkPHP)無(wú)法正常運(yùn)行。

4、

在php.ini上設(shè)置了:open_basedir=/home:/tmp/:/proc/

重啟php-fpm

訪(fǎng)問(wèn)網(wǎng)頁(yè),按ctrl + F5頻繁刷新的時(shí)候,會(huì)報(bào) Access Denied錯(cuò)誤。Access Denied是偶爾才會(huì)出現(xiàn),不是一直403 。

nginx錯(cuò)誤日志記錄:

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.

php有什么用

php是一個(gè)嵌套的縮寫(xiě)名稱(chēng),是英文超級(jí)文本預(yù)處理語(yǔ)言,它的語(yǔ)法混合了C、Java、Perl以及php自創(chuàng)新的語(yǔ)法,主要用來(lái)做網(wǎng)站開(kāi)發(fā),許多小型網(wǎng)站都用php開(kāi)發(fā),因?yàn)閜hp是開(kāi)源的,從而使得php經(jīng)久不衰。

以上就是“nginx php403錯(cuò)誤如何解決”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

標(biāo)題名稱(chēng):nginxphp403錯(cuò)誤如何解決
文章路徑:http://muchs.cn/article24/ihceje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)建站公司、手機(jī)網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷(xiāo)推廣、域名注冊(cè)、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)