nginx+php 訪問靜態文件例如js、css等出現403 Access denied. 問題筆記


在新搭建的web服務中訪問靜態文件出現了403,  響應Access denied. 問題截圖:

 

 

 

下面是nginx 的配置:

 1 server
 2 {
 3        listen       8010;
 4        server_name xxx.xxx.xxx;
 5        index index.html index.htm index.php;
 6        root  /xxx/xxxx/xxxx;
 7 
 8        location ~ .*\.(php|php5)?
 9        {
10            fastcgi_pass  unix:/dev/shm/php-cgi.sock;
11            fastcgi_index index.php;
12            include fastcgi.conf;      
13        }
14        
15        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|data|js|css|html|htm|ico)$  
16        {
17              expires      1d;
18        }   
19       
20        
21        
22 
23        access_log /xxx/xxx/nginx_logs/xxx_access.log main;
24 }

 在網上找了些方法:

1、修改php-fpm.conf中的security.limit_extensions

2、修改php.ini     cgi.fix_pathinfo = 0 改為 "1"

最后發現設置了security.limit_extensions 但是根本不解析js和css文件,導致頁面樣式混亂。

感覺還是nginx配置的問題,應該是所有的請求全部都走了php導致的,仔細查看nginx配置發現是這一行:location ~ .*\.(php|php5)?     少了$,

? 是0次或1次,所以在0次的時候並且沒有以php結尾的請求也進了php,導致沒有走下邊的邏輯。

所以還是粗心導致的bug,記錄在此,如有遇到同樣問題的同學可以少走些彎路。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM