在新搭建的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,记录在此,如有遇到同样问题的同学可以少走些弯路。