使用 wp-fail2ban 提高 wordpress 站点安全性

wp-fail2ban 是 wordpress 上一款与 fail2ban 集成的,提高 wordpress 站点安全性的插件。

安装:

插件>安装新插件 中搜索“wp-fail2ban”,安装如上图所示插件并启用。

安装完成后,ssh 连接到你博客的 vps 上。

配置:

参考插件的 配置文档 ,以使用 systemd 的 debian12 为例。

确保你的 vps 上已经安装了 fail2ban。如果没有安装,可以参考我的这篇博文进行安装和配置。

复制你的 网站根目录/wp-content/plugins/wp-fail2ban/filters.d/ 下的所有文件到 /etc/fail2ban/filters.d/ 目录下。

sudo cp 网站根目录/wp-content/plugins/wp-fail2ban/filters.d/*.conf /etc/fail2ban/filter.d/

修改你网站根目录下的 wp-config.php 文件,在末尾添加以下内容:

// Make sure we're not using the short ("wp") tag
define('WP_FAIL2BAN_SYSLOG_SHORT_TAG', false);

// Don't include the HTTP host in the tag
define('WP_FAIL2BAN_SYSLOG_TAG_HOST', false);

/* That's all, stop editing! Happy blogging. */

随后,保存退出。切换目录到 /etc/fail2ban/jail.d 。在该目录下新建一个名为 wordpress.conf 的配置文件,并添加以下内容:

[wordpress-hard]
enabled = true
filter = wordpress-hard
backend = systemd
journalmatch = SYSLOG_IDENTIFIER=wordpress
maxretry = 1
port = http,https

[wordpress-soft]
enabled = true
filter = wordpress-soft
backend = systemd
journalmatch = SYSLOG_IDENTIFIER=wordpress
maxretry = 3
port = http,https

完成后,保存退出并重新加载 fail2ban 服务。

sudo systemctl reload fail2ban

使用命令

systemctl status fail2ban

查看 fail2ban 是否正常运行。使用命令

sudo fail2ban-client status

查看新配置是否已添加。成功添加后输出如下图:

至此,wp-fail2ban 已经开始保护你的 wordpress 网站了。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注