yum安装Apache服务后配置简单的basic认证

[root@xxx-xxx-xxx src]# yum install httpd
依存性を解決しました

=============================================================================================
 Package                                 アーキテクチャー                   バージョン                                        リポジトリー                         容量
=============================================================================================
インストール中:
 httpd                                   x86_64                             2.4.6-89.el7.centos.1                             updates                             2.7 M
依存性関連でのインストールをします:
 apr                                     x86_64                             1.4.8-3.el7_4.1                                   base                                103 k
 apr-util                                x86_64                             1.5.2-6.el7                                       base                                 92 k
 httpd-tools                             x86_64                             2.4.6-89.el7.centos.1                             updates                              91 k
 mailcap                                 noarch                             2.1.41-2.el7                                      base                                 31 k

トランザクションの要約
=============================================================================================
インストール  1 パッケージ (+4 個の依存関係のパッケージ)

 

[root@xxx-xxx-xxx src]# rpm -qa |grep http
httpd-tools-2.4.6-89.el7.centos.1.x86_64
httpd-2.4.6-89.el7.centos.1.x86_64

 

[root@xxx-xxx-xxx httpd]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

[root@xxx-xxx-xxx conf]# systemctl start httpd
[root@xxx-xxx-xxx conf]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 金 2019-08-09 17:50:37 JST; 42s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 25686 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq25686 /usr/sbin/httpd -DFOREGROUND
           tq25687 /usr/sbin/httpd -DFOREGROUND
           tq25688 /usr/sbin/httpd -DFOREGROUND
           tq25689 /usr/sbin/httpd -DFOREGROUND
           tq25690 /usr/sbin/httpd -DFOREGROUND
           mq25691 /usr/sbin/httpd -DFOREGROUND

 8月 09 17:50:37 xxx-xxx-xxx systemd[1]: Starting The Apache HTTP Server...
 8月 09 17:50:37 xxx-xxx-xxx httpd[25686]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set th...is message
 8月 09 17:50:37 xxx-xxx-xxx systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

[root@xxx-xxx-xxx conf]# systemctl stop httpd

 

参考

修改Apache的配置文件/etc/httpd/conf/httpd.conf,对需要认证的资源所在的目录进行配置。
cd /etc/httpd/conf/
cp -ip httpd.conf httpd.conf.bak190809
vi httpd.conf
    注释这2行配置:
    # Options Indexes FollowSymLinks
    # AllowOverride None
    
    在注释掉的AllowOverride None这行配置后追加以下配置:
    # add begin
    Options Indexes FollowSymLinks
    AllowOverride authconfig
    Order allow,deny
    Allow from all
    # add end

在限制访问目录/var/www/html下创建文件.htaccess。
cd /var/www/html
vi .htaccess
AuthName "Auth!!!!!!"
AuthType basic
AuthUserFile /var/www/html/members.txt
require valid-user

说明:.htaccess文件中常用的配置选项有以下几个:
  1) AuthName:定义提示信息,用户访问时提示信息会出现在认证的对话框中
  2) AuthType:定义认证类型,在HTTP1.0中,只有一种认证类型:basic。在HTTP1.1中有几种认证类型,如:MD5
  3) AuthUserFile:定义包含用户名和密码的文本文件,每行一对
  4) AuthGroupFile:定义包含用户组和组成员的文本文件。组成员之间用空格分开,如:group1:user1 user2
  5) require命令:定义哪些用户或组才能被授权访问。如:
  require user user1 user2 (只有用户user1和user2可以访问)
  requires groups group1 (只有group1中的成员可以访问)
  require valid-user (在AuthUserFile指定的文件中的所有用户都可以访问)

利用Apache附带的程序htpasswd,生成包含用户名和密码的文本文件:/var/www/html/members.txt
htpasswd -bc /var/www/html/members.txt xxxx xxxx1234  #第一次添加用户时member.txt文件不存在,需要用-c选项创建文件
htpasswd -b /var/www/html/members.txt xxxx xxxx1234

cat /var/www/html/members.txt
xxxx:$cpr1$J2M/x2/p$Nb9wDpNWzKxmHEgAvAKPt0

确认关闭httpd的自启动!
systemctl is-enabled httpd.service
systemctl disable httpd.service
systemctl is-enabled httpd.service

重启服务进行访问测试:
systemctl status httpd.service
systemctl restart httpd.service
systemctl stop httpd.service
systemctl status httpd.service


转载于:https://www.cnblogs.com/tobyhan/p/11351281.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值