Apache 添加BasicAuth

6 篇文章 0 订阅
1 篇文章 0 订阅
Apache中使用BasicAuth时,需要
mod_auth_basic.so
mod_authn_file.so
mod_authz_user.so

首先查看模块是否正常安装:


/path/to/apache/bin/httpd -l

没有安装时:
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authz_user.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authn_file.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_auth.c


之后,编辑httpd.conf,添加:

LoadModule auth_basic_module  modules/mod_auth_basic.so
LoadModule authn_file_module  modules/mod_authn_file.so
LoadModule authz_user_module  modules/mod_authz_user.so

创建密码文件:

1 create passwd file
sudo /path/to/apache/bin/htpasswd -c /var/www/somewhere/passwd USERNAME
#input passwd for USERNAME


2 add this lines in httpd.conf


<Location /path_toadd_auth>
        Order deny,allow
        Allow from all
        AuthType Basic
        AuthName "Who R U?"
        AuthBasicProvider file
        AuthUserFile /var/www/somewhere/passwd
        Require valid-user
</Location>


3 restart your apache.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 CentOS 7.9 上配置 Apache 模块 mod_auth_external 的步骤如下: 1. 安装必要的软件包 使用以下命令安装必要的软件包: ``` sudo yum install httpd httpd-devel mod_ssl gcc ``` 2. 下载 mod_auth_external 模块 从 mod_auth_external 的官方网站(http://code.google.com/p/mod-auth-external/)下载 mod_auth_external 模块。 3. 编译和安装模块 解压下载的 mod_auth_external 模块,进入解压后的目录,使用以下命令编译和安装模块: ``` sudo apxs -i -a -c mod_authnz_external.c sudo apxs -i -a -c mod_authz_unixgroup.c ``` 4. 配置 Apache 打开 Apache 的主配置文件 /etc/httpd/conf/httpd.conf,在文件末尾添加以下内容: ``` LoadModule authnz_external_module modules/mod_authnz_external.so LoadModule authz_unixgroup_module modules/mod_authz_unixgroup.so AddExternalAuth pwauth /usr/sbin/pwauth SetExternalAuthMethod pwauth pipe <Directory "/var/www/html"> AuthType Basic AuthName "Restricted Content" AuthBasicProvider external AuthExternal pwauth Require valid-user </Directory> ``` 在上面的配置中,我们将 mod_auth_external 模块加载到 Apache 中,并设置了一个外部认证的命令 pwauth,该命令将验证用户的用户名和密码。我们还配置了一个受限内容的目录 /var/www/html,该目录需要基本身份验证,并使用外部认证提供程序 pwauth 进行认证。 5. 重启 Apache 使用以下命令重启 Apache: ``` sudo systemctl restart httpd ``` 完成以上步骤后,您的 Apache 就已经配置了 mod_auth_external 模块,并且可以使用外部认证来验证用户身份了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值