日期:2014-05-17  浏览次数:20569 次

nginx目录权限控制求助

server {
listen       80;
server_name  admin.my.com;

location / {
root   D:/www/webroot;
index  index.php;
}

        error_page 404 = http://admin.my.com/error.html;

location ~ \.php$ {
root D:/www/webroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME  D:/www/webroot$fastcgi_script_name;
include fastcgi_params;
}
}


fastcgi.conf如上配置

我这个系统的url结构(非伪静态,只是在入口文件中作了转换):如:
http://admin.my.com/index.php/Index/image
_code
http://admin.my.com/index.php/Admin/edit_config
http://admin.my.com/index.php/News/add
……
index.php是入口文件,单一入口

但是问题来了,当我访问http://admin.my.com/index.php/Index/image_code的时候
事实上文件路径指向了:D:/www/webroot/index.php/Index/image_code/index.php
因为上面的location中配置了:index  index.php;  大概url中的后缀名不是php或者html或者其他“物理存在”的文件,都会自动加上index.php吧,是么????????????

我的目的就是:无论index.php后面有多少个斜杠构成的url,入口文件只能是前面的index.php,而不是把后面的参数认成目录并自动加上index.php。

我知道这个url结构很不规则,但目前改起来比较费事,时间关系,所以在想有没有办法通过nginx配置来解决。求大神,求大仙,谢谢。

感觉还是apache好用,一下子就搞定了:

<VirtualHost *:80>
    ServerAdmin admin@yahoo.com.cn
    DocumentRoot /
    ServerName admin.my.com
    Alias /  "D:/www/webroot/"
    <Directory "D:/www/webroot/">
Options  FollowSymLinks MultiViews ExecCGI
   
Order allow,deny
       Allow from all 
    </Directory>
   ErrorLog logs/admin-error.log
   #CustomLog logs/admin-access.log common
</VirtualHost>
nginx apache server

------解决方案--------------------
location ~ \.php$
去掉php后的 $  正则中$意味着结束。去掉也就告诉了nginx把所有.php*文件交给fpm处理,而不只是.php。
然后将执行文件名改为index.php
fastcgi_param    SCRIPT_FILENAME  D:/www/webroot/index.php;
剩下的就看你的应用了。

这个算是比较简单的配置,要想了解更完善的方法,自己去搜吧,这方面的说明真太多了