WordPress限制ip访问(附Apache和Nginx实现方法)

itlao6 原创 工具&方法评论781字数 724阅读2分24秒阅读模式

最近wordpress总是被一些网站快排访问,导致统计中的搜索词大量出现xx快排、seo一类的词汇,看着挺烦的,而且网站跳出率直线升高,所以在统计网站中屏蔽了对应的ip。

但是想着,这只能算是治标,不能治本,他照样访问我的站点,所造成的服务器资源浪费、流量浪费等依然存在,所以想着直接在站点上禁止访问。文章源自IT老刘-https://itlao6.com/5616.html

以下是我的配置,centos搭建的wordpress站点,修改htaccess配置后,用自己ip验证了已生效。文章源自IT老刘-https://itlao6.com/5616.html

order allow,deny
# 禁止ip地址(可配置多条)
deny from 192.168.0.1
deny from 192.127.0.1
# 除此之外均允许
allow from all

Apache配置

打开.htaccess文件(如果没有创建,可在本地任意创建一个空文档,然后上传至FTP后改名.htaccess),加入以下代码:文章源自IT老刘-https://itlao6.com/5616.html

order allow,deny
# 禁止ip地址
deny from 192.168.0.1
# 禁止ip段
deny from 192.168.0.0/255
#允许ip段
allow from 192.168.1.0/255
# 允许ip地址
allow from 192.168.1.1
# 除此之外均允许
allow from all
# 除此之外均禁止
deny from all

Nginx配置

打开nginx.conf文件,加入以下代码:文章源自IT老刘-https://itlao6.com/5616.html

# 禁止ip地址
deny 192.168.0.1
# 禁止ip段
deny 192.168.0.0/255
#允许ip段
allow 192.168.1.0/255
# 允许ip地址
allow 192.168.1.1
# 除此之外均可以
allow all
# 除此之外均禁止
deny all
文章源自IT老刘-https://itlao6.com/5616.html文章源自IT老刘-https://itlao6.com/5616.html
weinxin
我的微信公众号
微信扫一扫关注公众号,不定时更新
itlao6
  • 本文由 发表于 2021年 7月 7日 17:52:30
  • 转载请务必保留本文链接:https://itlao6.com/5616.html
评论  0  访客  0
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定