NGINX跳过位置身份验证

时间:2021-06-03 13:55:35

标签: nginx

我们希望我们的整个服务器免受匿名访问,除了一个端点 /public。但是,我们看到位置 /ping 被匿名访问,状态为 200。

为什么?

我们当然不需要在每个位置块上放置身份验证指令吗?

server {

  location /ping {
    return 200 'OK'; # Should not be available anonymously!
  }

  location = /public {
    auth_basic off;
    return 200 'OK'; # Should be available anonymously
  }

  # Users must authenticate in general
  satisfy any;
  auth_basic "Authentication";
  auth_basic_user_file /etc/my/.htpasswd;


}

根据文档,这应该有效:

<块引用>

或者,您可以使用基本身份验证限制对整个网站的访问,但仍将某些网站区域设为公开。在这种情况下,指定 auth_basic 指令的 off 参数以取消从上层配置级别的继承:

server {
    ...
    auth_basic           "Administrator’s Area";
    auth_basic_user_file conf/htpasswd;

    location /public/ {
        auth_basic off;
    }
}

1 个答案:

答案 0 :(得分:0)

感谢@Richard Smith 的提示 - 我们需要一种解决方法,因为 import discord from discord.ext import commands @client.command(pass_context=True, aliases=["dm", "message", "directmessage"]) @commands.has_role("pog") async def msg(ctx, member: discord.Member, *, message): em = discord.Embed(title=f"Incoming Message from {ctx.author}", description=f"{str(message)}", color=discord.Colour.blue()) await member.send(embed=em) client.run('TOKEN') 在任何其他指令之前执行。

return