产品服务AMH 免费服务器主机面板SSL证书 免费SSL证书申请 担保单 免费安全、零费率交易平台编程助手免费智能写代码、翻译AMYSQL 免费MySQL管理工具

AMH 社区首页

 AMH社区 - 开放自由有价值的社区

[求助帖] 求助:lnmp环境下如何设置某个网站使用用户名和密码验证...

诸葛御风
金牌会员
5691.90 价值分

诸葛御风 发表于 2015-03-22 22:50:27
本帖最后由 诸葛御风 于 2015-3-22 23:45 编辑

求助:lnmp环境下如何设置某个网站使用用户名和密码验证后登录
譬如xxx.com使用的amh5.1面板配置了lnmp环境并使用了nginx反向代_理
但是这个代_理我不想让我允许名单之外的人使用
那我需设置nginx登录验证
amh面板有没有什么快捷的办法?
---------华丽丽的分割线---------
已经自行解决
有时我们会有这么一种需求,就是你的网站并不想提供一个公共的访问或者某些页面不希望公开(譬如某个反向代_理),我们希望的是某些特定的客户端可以访问。那么我们可以在访问时要求进行身份认证,就如给你自己的家门加一把锁,以拒绝那些不速之客。
实验环境:
现在开通了一个内部使用反向谷歌学术代_理(amh,lngx),要求所有人查看网页信息之前都必须要输入内定的用户名及密码方可浏览网页
有关nginx下虚拟主机的搭建请amh,地址http://amh.sh。这里使用之前搭建的虚拟主机xs.wyk.so进行测试。
一、查看当前系统参数

[*]
[root@scholar ~]# uname –r //查看系统内核版本号
[*]2.6.32-042stab104.1
[*][root@scholar ~]# cat /etc/centos-release
CentOS release 6.5 (Final)

二、编辑虚拟主机配置文件(位置/home/wwwroot/lngx_name/vhost/

server {
listen 80; #listen end
server_name amh.sh; #server_name end
index index.html index.htm index.php; #index end
auth_basic "secret"; //虚拟主机认证命名
auth_basic_user_file /home/wwwroot/lngx_name/domain/amh.sh/passwd.db;


root /home/wwwroot/lngx_name/domain/amh.sh/web; #root end
include /home/wwwroot/lngx_name/rewrite/amh.conf; #rewrite end
proxy_cache lngx_name; #proxy_cache end
proxy_temp_path /home/wwwroot/lngx_name/cache_temp;
proxy_cache_key $scheme://$host$request_uri;
proxy_cache_valid 200 304 12h; #cache_valid end
proxy_connect_timeout 60s; #connect_timeout end

location / {
default_type text/html;
subs_filter_types text/css text/xml; #subs_filtert end
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://code.amh.sh; #header_referer end
proxy_set_header Host code.amh.sh; #header_host end
proxy_pass http://code.amh.sh; #proxy_pass end
proxy_set_header Accept-Encoding "";
}
access_log off; #access_log end
error_log /dev/null; #error_log end
}
红色为添加部分
三、生成passwd.db文件
因为主机没有htpasswd命令所以使用http://tool.oschina.net/htpasswd提供的工具生成htpasswd。everedit编辑db文件。上传至web目录下
http://www.wuyukang.com/wp-content/uploads/2015/03/QQ%E6%88%AA%E5%9B%BE20150322232711.png
四、重载nginx服务

http://www.wuyukang.com/wp-content/uploads/2015/03/QQ%E6%88%AA%E5%9B%BE20150322234147.png
五、测试
http://www.wuyukang.com/wp-content/uploads/2015/03/QQ%E6%88%AA%E5%9B%BE20150322233117-1024x552.png
发表地址http://www.wuyukang.com/amh-nginx-lngx-authority.php


2015-03-22 22:50:27 1

amysql
创始人
99530.81 价值分

感谢分享。
  支持 (0分)  反对 (0分)
回复  2015-03-23 12:19:33 2

AMH面板 - 好用高效低占用、安全可靠极稳定

 1  (总1页)
AMH社区列表
用户服务中心