欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

nginx目录权限控制

程序员文章站 2022-05-26 22:24:15
...
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好用,一下子就搞定了:


ServerAdmin admin@yahoo.com.cn
DocumentRoot /
ServerName admin.my.com
Alias / "D:/www/webroot/"

Options FollowSymLinks MultiViews ExecCGI

Order allow,deny
Allow from all

ErrorLog logs/admin-error.log
#CustomLog logs/admin-access.log common

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

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • nginx目录权限控制
  • 专题推荐