nginx如何配置只允许访问index.php其它的一律不能访问?
比如 我目录中有index.php 和test.php等 文件
如何配置只允许访问 index.php, 而test.php不能访问
server
{
listen 80;
server_name 192.168.16.86;
index index.php;
root /home/wwwroot/web;
include enable-php.conf;
location = /index.php {
try_files $uri $uri/ /index.php?$query_string;
}
location / {
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/logs/web.log;
}
我这个配置可以吗
也还是要分情况,如果你只想 index.php 被访问,其他所有路径都屏蔽,那可以像下面这样配置
那如果你只想所有 php 中,只有 index.php 被访问,而其他 php 不允许,但是对于其他请求又正常放行(比如静态资源),那就要调整一下。