三种方式修改wordpress后台登录链接,避免太容易被猜到

为何要修改后台登录链接?

wordpress作为非常流行的cms开源软件,默认的后台登录链接众所周知,经常有攻击者想暴力破解后台。为增加安全性,不那么容易被攻击者猜到后台链接,所以建议修改。

  1. 通过插件方式,支持改后台链接的插件很多,本人未亲测,网上搜索到说
    1. Settings WPS Hide Login
    2. Limit Login Attempts
    3. Theme My Login
    4. Stealth Login Page
    5. Protected wp-login
  2. 使用wordpress的朋友都知道插件过多必然会导致网站运行变慢,这不论是SEO还是其他方面都是非常不利的。因此不建议通过插件方式修改。这边介绍另一种,代码方式,在主题下的functions.php文件中添加如下代码,这样修改如果更换主题将失效,经本人亲测修改wp-includes目录下的functions.php也一样有效,,修改之后的后台登录链接示例:http://domain/wp-login.php?word=exp
//保护后台登录
 add_action('login_enqueue_scripts','login_protection');  
 function login_protection(){  
     if($_GET['word'] != 'exp')header('Location: http://domain/');  
 }

下面来介绍下本人使用的第三种修改方法,也是来自网络。具体操作如下:

  1. 将wp-login.php文件命名 xxxx.php,怕出问题的自行备份该文件。
  2. 编辑命名后的xxxx.php将wp-login全部替换为xxxx。
  3. 编辑wp-includes/目录下的general-template.php文件把其中的wp-login全部替换为xxxx。
  4. 替换之后找到该文件的function wp_login_url函数,将该函数中 $login_url = site_url(‘xxxx.php’, ‘login’); 修改为 $login_url = site_url(‘index.php’, ‘login’); 这样修改之后攻击者直接通过login访问会跳转到首页。
  5. 在nginx配置文件中server节点中添加rewrite /bg$ $scheme://$host/xxxx.php; 重启nginx。这样通过http://domain/bg就可以到登录页面了。bg就是自定义的后台登录链接,或者直接访问xxxx.php也是可以的。使用apache的同学也可以参考相应的方法,修改对应配置,增加rewrite规则实现自定义登录链接。这一步可以不做。就是直接通过访问xxxx.php来登录。

经本人验证,若第三种方式与第二种结合,那么登录链接变成http://domain/bg?word=exp才能正常进入登录界面。安全性进一步提升。

附上配置示例代码

server {
    listen       80;
    server_name  xxxx.top www.xxxx.top;
    root /var/www/html/xxxx.top;
    location / {
        try_files $uri $uri/ /index.php?$args;
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
    }
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite /bg$ $scheme://$host/xxxx.php;

    location ~ \.php$ {
           try_files $uri =404;

           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
          }
}

You may also like...

发表回复

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

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据