Home  >  Article  >  php教程  >  Nginx+php fastcgi 发生 Access Denied

Nginx+php fastcgi 发生 Access Denied

WBOY
WBOYOriginal
2016-06-06 19:46:151139browse

原因分析: php官方从5.3.9开始,加入了一个配置security.limit_extensions(/usr/local/php/etc/php-fpm.conf),默认状态下只允许执行扩展名为.php的文件,造成了其他类型的文件不支持的问题。 如果你请求的 地址是 css js png这种资源 会被 php 拒绝,如

原因分析:

php官方从5.3.9开始,加入了一个配置"security.limit_extensions"(/usr/local/php/etc/php-fpm.conf),默认状态下只允许执行扩展名为".php"的文件,造成了其他类型的文件不支持的问题。

如果你请求的 地址是  css js png这种资源 会被 php 拒绝,如果你请求的是 http://localhost/user   (暗含  http://localhost/user/index.php)也是不行的。


解决方式

1,有的人修改 php的配置文件 将 允许的扩展 都加上 比如security.limit_extensions=.php .html .js .css .jpg .jpeg .gif .png .htm#

但是这样其实是不好的 因为静态资源本来就不应该让php fast-cgi处理

2,(推荐)使用nginx的rewrite

location  ~ \.(js|css|gif|jpg|jpeg|png)$ {
    root   D:/tmp;
}
location  ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:3344;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  D:/tmp/$fastcgi_script_name;
            include        fastcgi_params;
}
location   / {
            root           D:/tmp/film;
            fastcgi_pass   127.0.0.1:3344;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  D:/tmp/film/$fastcgi_script_name;
            include        fastcgi_params;
            rewrite        ^(.*)$      $1/index.php;
}

如此可以较好解决问题 第一个location过滤类型 可能不够,可以根据自己的需求添加

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn