nginx如何配置只允许访问index.php其它的一律不能访问?

 

问题描述:

nginx如何配置只允许访问index.php其它的一律不能访问?
比如 我目录中有index.php 和test.php等 文件
如何配置只允许访问 index.php, 而test.php不能访问


 

第 1 个答案:

也还是要分情况,如果你只想 index.php 被访问,其他所有路径都屏蔽,那可以像下面这样配置

location = /index.php {
    # TODO 对于 index.php 的处理
}

location / {
  deny all;
}

那如果你只想所有 php 中,只有 index.php 被访问,而其他 php 不允许,但是对于其他请求又正常放行(比如静态资源),那就要调整一下。

location / {
  # TODO 其他资源
}

location ~ \.php$ {
  # 拒绝所有 .php 文件的访问(除了 /index.php)
  deny all;
}

# 仅允许 /index.php 的访问
location = /index.php {
  # 对于 index.php 的处理
}

为什么获取不到表单的值,而且还多了两个字段