博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LAMP构建-Apache用户认证(输入密码才能访问)
阅读量:7015 次
发布时间:2019-06-28

本文共 2009 字,大约阅读时间需要 6 分钟。

LAMP构建-Apache用户认证(输入密码才能访问)

输入网址后不会直接显示网站,而是提示要求你输入密码才能访问;

编辑httpd-vhosts.conf文档

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/wwwroot/szl.com" ServerName szl.com ServerAlias www.szl.com
; //指定认证的目录 AllowOverride AuthConfig //这个相当于打开认证的开关 AuthName "szl.com user auth" //自定义认证的名字,作用不大 AuthType Basic //认证的类型,一般为Basic AuthUserFile /data/.htpasswd //指定密码文件所在位置 require valid-user //指定需要认证的用户为全部可用用户
ErrorLog "logs/szl.com-error_log" CustomLog "logs/szl.com-access_log" common

创建密码文件

创建密码文件与用户名admin

/usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd admin

重新加载配置-t,graceful

/usr/local/apache2.4/bin/apachectl -t/usr/local/apache2.4/bin/apachectl graceful

绑定hosts,浏览器测试

LAMP构建-Apache用户认证(输入密码才能访问)

curl命令服务器本机测试

需要输入账号密码就提示代码401

正常为代码200
curl -x127.0.0.1:80 szl.com

[root@shu-test ~]# curl -x127.0.0.1:80 szl.com401 Unauthorized

Unauthorized

This server could not verify that youare authorized to access the documentrequested. Either you supplied the wrongcredentials (e.g., bad password), or yourbrowser doesn't understand how to supplythe credentials required.

[root@shu-test ~]#

针对单个页面文件进行加密

修改httpd-vhosts.conf配置文档

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/wwwroot/szl.com" ServerName szl.com ServerAlias www.szl.com#
;
AllowOverride AuthConfig AuthName "szl.com user auth" AuthType Basic AuthUserFile /data/.htpasswd require valid-user
#
ErrorLog "logs/szl.com-error_log" CustomLog "logs/szl.com-access_log" common

创建admin.php文件

vim /data/wwwroot/szl.com/admin.php
[root@shu-test ~]# cat /data/wwwroot/szl.com/admin.php
[root@shu-test ~]#

测试

测试admin.php

需要输入密码
测试szl.com,不需要账号密码;
LAMP构建-Apache用户认证(输入密码才能访问)

转载于:https://blog.51cto.com/shuzonglu/2082186

你可能感兴趣的文章
linux命令学习(68 69)-tree finger
查看>>
写给同事的前端学习路线
查看>>
我的友情链接
查看>>
Global Azure上创建SSTP模式***配置介绍
查看>>
SQL Server 2016 Failover Cluster+ ALwaysOn(二)
查看>>
spring源码--依赖注入
查看>>
rhel7配置多用户tiger vnc server
查看>>
iOS播放系统声音
查看>>
const 命令
查看>>
我的友情链接
查看>>
linux系统root口令丢失
查看>>
菜鸟学Linux 第088篇笔记 配置heartbeat基于crm管理
查看>>
我的友情链接
查看>>
多线程爬虫1
查看>>
OSPF区域划分配置实例
查看>>
CDH5.10.0 离线安装(共3节点)
查看>>
Android第六课 安装异常处理
查看>>
输入n个整数,输出其中最小的k个
查看>>
web.xml 中的listener、 filter、servlet 加载顺序及其详解
查看>>
C#反射之Assembly.Load,Assembly.LoadFile 与 Assembly.LoadFrom方法介绍
查看>>