• Linux CentOS 8(HTTP综合案例-用户登录)



    Linux CentOS 8(HTTP-用户登录)


    当服务器端希望客户端以特定的用户进行访问访问时,可以运用HTTP的用户登录功能。HTTP 有四种对用户身份验证的方式,分别为 BASIC 认证,DIGEST 认证,SSL 客户端认证和 Web 表单认证。以下以 BASIC 认证为例,实现的操作步骤如下:

    步骤1、 创建一个名为 testuser 的用户

    HTTP 自带的 htpasswd 命令就可以生成授权用户数据文件,最后一个参数即为登录账号名。第一次创建用户要用到 -c 参数,以后添加用户,不用 -c 参数,表示可以在已有的文件里添加新用户。

    [root@ localhost conf.d]# htpasswd -c /etc/httpd/conf.d/htpasswd testuser
    New password: 
    Re-type new password: 
    Adding password for user testuser
    
    ///etc/httpd/conf.d/htpasswd表示认证文件的路径,可以自己选定其他路径。
    
    [root@ localhost conf.d]# htpasswd -m /etc/httpd/conf.d/htpasswd testuser
    //修改某个用户的密码
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    步骤2、 创建网站内容

    [root@localhost ~]# mkdir /test
    [root@localhost ~]# echo 'private file' > index.html
    
    • 1
    • 2

    步骤3、 修改配置文件

    修改配置文件,如图1所示。

    [root@localhost ~]# vim /etc/httpd/conf/httpd.conf 
    
    • 1

    在这里插入图片描述

    图1

    参数解析:

    #<Directory "/test"> #在这个标签里添加针对/test设置用户认证
    #AuthName "please enter the password"  // 弹出对话框的提示
    #AuthType Basic                        // 认证类型
    #AuthUserFile /etc/httpd/conf.d/htpasswd   // 密码文件路径
    #require valid-user                    // 限制为所有合法用户
    
    • 1
    • 2
    • 3
    • 4
    • 5

    步骤4、 重启 httpd 服务

    [root@localhost ~]# systemctl restart httpd
    
    • 1

    步骤5、 放通防火墙服务

    [root@localhost ~]# firewall-cmd --permanent --add-service=82/tcp
    [root@localhost ~]# firewall-cmd --reload
    [root@localhost ~]# setenforce 0
    
    • 1
    • 2
    • 3

    步骤6、 测试

    (1)认证页面效果如图2所示。
    在这里插入图片描述

    图2

    (2)如果不是指定用户,或者用户名密码错误则会认证失败,如图3所示。
    在这里插入图片描述

    图3

    制作成员: 何嘉愉
    排版: 裕新
    初审: 杨佳佳
    复审: 二月二
    在这里插入图片描述


    点击下方“正月十六工作室”查看更多学习资源

    正月十六工作室

  • 相关阅读:
    linux下安装工具——yum
    lnmp环境部署
    如何将带GPS的网络化的软件定义无线电接收机应用于分布式和移动频谱监测?(一)
    Pytorch-CNN-Mnist
    LiteIDE主题定制教程
    智能金融决策策略,规则引擎在大数据金融行业的实战案例
    网站SEO效果分析
    使用spring boot集成shardingsphere分库分表简易测试
    激动人心,2022开放原子全球开源峰会报名火热开启
    【Linux集群教程】05 集群存储 - NFS
  • 原文地址:https://blog.csdn.net/hjx020/article/details/125060528