简介
相信很多朋友在安装完 LNMP、Oneinstack 等的一键安装包之后,打开 IP 地址都会出现探针的页面吧。很多时候我们可以借助这个页面来查看 PHP 的参数,服务器的运行状态。但是很多情况下我们不希望别的人看到它。这时,我们就需要建立一个简单的用户验证窗口。
方法
本文以Nginx
为例,适用于大部分 LNMP 一键包(包括 Oneinstack、LNMP.org)。
第一步
生成用户密码文件。
我们默认 Nginx 安装在 /usr/local/nginx/ 目录下,于是我们新建一对用户密码:
printf "user:$(openssl passwd -crypt passwd)\n" >> /usr/local/nginx/conf/htpasswd
//其中user替换为你的用户名 passwd替换为你的密码
命令执行完成之后,/usr/local/nginx/conf/htpasswd 文件就储存了一对用户名密码,我们将在 Nginx 配置里面用这个文件的用户名密码信息作为验证条件。
第二步
配置 Nginx location 区块
这里以 test 为例,编辑
/usr/local/nginx/conf/vhost/test.conf
在配置文件中添加如下代码:
location ~ ^/M.IUI/.* {
//其中~ ^/M.IUI/.*代表 M.IUI目录下访问需要密码,其他目录则不需要密码
//如需要全目录加密则直接 location / {
auth_basic "login...";
auth_basic_user_file htpasswd;
autoindex on;
}
然后我们保存退出,重载下 Nginx:
service nginx reload
接着打开我们的页面,就能看到这样的验证提示框了,此时我们能够输入之前设定的用户名和密码,就能进入访问。否则就无法登录.
最新评论
Hi to all, it's genuinely a fastidious for me to visit this web page, it contains valuable Informati
Hi it's me, I am also visiting this site regularly, this site is actually nice and the people are
Hello. And Bye.
This is very interesting, You're a very skilled blogger. I've joined your feed and look forward to
王某发来贺电
91porn携全体用户发来贺电,祝老托开业大吉!
头像测试
一位不愿透漏姓名的热心网友