使用.htaccess限制从网站中删除特定IP

时间:2017-12-22 15:18:57

标签: .htaccess nginx webserver access restriction

我想授予对托管网站(nginx)的公共访问权限,并排除访问它的特定IP地址范围(123.456)。

简单地说:IP-Range 123.456的每次访问都应该通过Promname for Username / Password来限制。这就是我想要的东西。

这是我的.htaccess。

AuthType Basic
AuthName "Go away!"
AuthUserFile /home/www/path-to-my/.htpasswd
Require valid-user
Order Allow,Deny
Allow from all
Deny from 123.456
Satisfy any

我使用它时得到的结果:

  • 公众访问成功
  • 从排除的IP范围=超时
  • 进行访问

1 个答案:

答案 0 :(得分:0)

据我所知.htaccess文件仅适用于apache web服务器而非nginx。

您需要使用a converter转换规则或自行完成。

在你的情况下:

# nginx configuration
auth_basic "Go away!";
auth_basic_user_file /home/www/path-to-my/.htpasswd;
deny 123.456;
satisfy any;

配置指令非常相似,但它们是不同的。