惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

Rat's Blog - Nginx

使用Nginx反向代理,自建CDN加速节点 - Rat's Blog LNMP环境下,利用Nginx反代Google网站的方法 - Rat's Blog Nginx环境下对部分网站做防盗链设置及外链的跳转 - Rat's Blog CentOS 7安装配置Nginx 1.10、PHP 5.6、MySQL 5.7教程 利用Nginx反向代理来简单镜像HTTP(S)网站的方法 - Rat's Blog LNMP环境下使用CDN后获取访客真实IP的方法 - Rat's Blog Nginx给网站添加用户认证配置( Basic HTTP authentication) - Rat's Blog Nginx环境开启ssl后强制https 301全部指向www的方法 - Rat's Blog 防止Linux VPS主机Nginx环境根目录被解析的方法 - Rat's Blog
Nginx环境使用auth_basic密码保护wordpress后台登录界面 - Rat's Blog
博主: Rat's · 2017-06-10 · via Rat's Blog - Nginx

说明:现在很多使用wordpress的人,或多或少都会出现后台被登录很多次的现象,运气不好就被进去了,通常大家都会通过修改wp-login文件来保护wordpress后台,但是这种方法有个不方便的地方就是每次WP升级就又要重改一遍,感觉很麻烦,不过使用Nginxauth_basic基本http验证功能可以保护web目录下的文件,于是我们就可以使用此文件来保护wp-login.php文件,效果就是进入后台之前,还需要验证成功,这样感觉很有效。这里以军哥的lnmp环境为例。
请输入图片描述

更多设置请参考:Nginx给网站添加用户认证配置( Basic HTTP authentication)

方法

1、生成用户名密码
进入网站:http://tool.oschina.net/htpasswd,然后输入用户名密码后选择Crypt加密算法。在vps上的/home目录下新建一个htpasswd文件,然后编辑htpasswd文件将刚才生成的用户名密码复制进去。可以通过Ftp工具完成,也可以执行这个命令:

#以下3种加密任选其一,记得修改用户名rats和密码moerats
#crypt加密
printf "rats:$(openssl passwd -crypt moerats)\n" >> /home/htpasswd

#apr1加密
printf "rats:$(openssl passwd -apr1 moerats)\n" >> /home/htpasswd

#MD5加密
printf "rats:$(openssl passwd -1 moerats)\n" >> /home/htpasswd

2、修改网站conf文件
这里我们用vim命令编辑,或者直接用WinSCP工具修改

vim /usr/local/nginx/conf/vhost/moerats.com.conf   

下面一段加到include enable-php.conf;后面

location = /wp-login.php {
auth_basic "Please enter your username and password";
auth_basic_user_file /home/htpasswd;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index wp-login.php;
include fastcgi.conf;
}

主要修改auth_basic_user_file这一行后面为你的密码文件位置就可以了。

3、重启Nginx生效

/etc/init.d/nginx restart

现在访问xxx.com/wp-login.php或者xxx.com/wp-admin应该都会弹出用户名密码的验证框就对了。


版权声明:本文为原创文章,版权归 Rat's Blog 所有,转载请注明出处!

本文链接:https://www.moerats.com/archives/170/

如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。