在新搭建的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,記錄在此,如有遇到同樣問題的同學可以少走些彎路。