Apache用户认证方法汇总(转载)_PHP

php中文网
发布: 2016-06-01 12:41:08
原创
1058人浏览过

Apache

叮当好记-AI音视频转图文
叮当好记-AI音视频转图文

AI音视频转录与总结,内容学习效率 x10!

叮当好记-AI音视频转图文 193
查看详情 叮当好记-AI音视频转图文
Apache用户认证方法汇总

一.基本的Apache用户认证方法:

若对某一目录下的文件如/home/ftp/pub需要做到用户认证,则在httpd.conf中加入下面的行

options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all


用在目录/home/ftp/pub下放文件.htaccess,内容如下:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user

用随Apache来的程序htpasswd 生成文件/etc/.passwd,每行一个用户名:密码

只要能提供正确的用户名和密码对,就允许登录访问,这是针对任何地址来的请求都要求提供用户名和密码认证。

二.针对部分网段或地址要求认证。

若公司LAN所在网段为192.168.0.0/24,且有一防火墙专线接入Internet,内部网卡的地址为192.168.0.1/32,则现在希望所有通过拨本地163通过防火墙上的apache反向代理向LAN上的另一WWW服务器访问时需要认证,而本地LAN上的用户不需认证。可以在httpd.conf中放入:
〈Directory /home/ftp/pub>
Options Indexes FollowSymLinks
AllowOverride AuthConfig
order deny,allow
deny from 192.168.0.1
〈/Directory>

且在/home/ftp/pub/.htaccess中放入:
AuthName "shared files"
AuthType Basic
AuthUserFile /etc/.passwd
require valid-user
satisfy any

三.对同一目录及其下的子目录有不同的权限,仅某些人可以存取一目录下的子目录。
如有一目录/home/ftp/pub/sales,有三个用户user1,user2,user3都需要用户名和密码进入/home/ftp/pub,但仅user1,user2能进入/home/ftp/pub/sales.则放下面的行到httpd.conf

〈Directory /home/ftp/pub>
Options Indexes
AllowOverride AuthConfig
order allow,deny
allow from all
〈/Directory>

〈Directory /home/ftp/pub/sales>
Options Indexes
AllowOverride AuthConfig
order allow,deny
allow from all
〈/Directory>

且看/home/ftp/pub/.htaccess为:
AuthName "shared files"
AuthType Basic
AuthUserFile /etc/.passwd
require valid-user

且看/home/ftp/pub/sales/.htaccess
AuthName "shared files"
AuthType Basic
AuthUserFile /etc/.passwd
AuthGroupFile /etc/.salesgroup
require group manager

且文件/etc/.passwd内容为:
user1:passwd1
user2:passwd2
user3:passwd3

且文件/etc/.salesgroup内容为:
manager: user1 user2
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号