• Nginx (可为容器)配置 BasicAuth 与访问


    创建认证信息

    在 Nginx 容器内部,下载安装 apache2-utils 。

    apt-get install apache2-utils
    

    创建用于保存认证信息的 .db 文件夹。

    mkdir /etc/nginx/basicauth/
    

    使用 apache2-utils 工具集中的 htpasswd 工具创建用于保存认证信息的 .db 文件。

    htpasswd -c /etc/nginx/basicauth/example_auth.db example_account_name
    New password: 
    Re-type new password:
    

    创建完成后,可查看认账信息:

    cat  /etc/nginx/basicauth/example_auth.db
    example_account_name:$aaaa$bbbbbbbbbb$ccccccccccccccccccc
    

    配置 .conf 文件

    对于 Nginx 的 .conf 配置文件,简单来说包含一大一小两个模块:

    server {
        server_name www.yogile.site;
        listen 80;
        ......
        location / {
            ......
        }
    }
    

    无视 location 映射规则

    如果想要无视 location 映射规则,对于监听的域名下所有 URL 的访问都添加 BasicAuth ,只需要在 location 前添加配置即可。

    server {
        server_name www.yogile.site;
        listen 80;
        ......
        auth_basic "上不上?";
        auth_basic_user_file /etc/nginx/basicauth/example_auth.db;
        location / {
            ......
        }
    }
    

    特定 location 映射规则

    要想针对监听的域名下特定 URL 的访问添加 BasicAuth ,只需要在目标 location 中添加即可。

    server {
        server_name www.yogile.site;
        listen 80;
        ......
        location / {
            auth_basic "上不上?";
            auth_basic_user_file /etc/nginx/basicauth/example_auth.db;
            ......
        }
    }
    

    在 URL 中认证登录

    有时候需要在软件中访问被 BasicAuth 认证的站点,要使用也非常简单。

    将用户名和密码由 : 英文冒号分割,加上 @ 添加到 https://blivechat 字符之间。

    Copyhttps://[用户名]:[密码]@blivechat.tools.yogile.site/room/7866049?......
    

    示例:

    Copyhttps://Account:Password@blivechat.tools.yogile.site/room/7866049?......
    

    将插入后的 URL 复制到 OBS 中,即可像往常一样使用,不用第二次认证。

    img

  • 相关阅读:
    电子招投标应用系统连载(一)-开标系统
    js实现一个简单钟表动画(javascript+html5 canvas)
    ,net core mvc 文件上传
    echarts显示X轴最后一个lable
    C# 解压gzip文件(.tgz)
    【转】C#计算两坐标点距离
    用file标签实现多图文件上传预览
    c#数据批量插入
    Asp.net 中ViewState,cookie,session,application,cache的比较
    ASP.NET MVC从请求到响应发生了什么
  • 原文地址:https://www.cnblogs.com/Yogile/p/15049795.html
Copyright © 2020-2023  润新知