zoukankan      html  css  js  c++  java
  • nginx做简单的登录认证

    比如要对 网站目录下的 test 文件夹 进行加密认证

    首先需要创建一个密码文件 例如 /root/pwd
    此文件的书写格式是
    用户名:密码
    每行一个账户
    并且 密码必须使用函数 crypt(3) 加密

    可以使用perl 为密码加密 新建 一个 pwdgen.pl 文件 其内容:

    #!/usr/bin/perl
    use strict;
    
    my $pw=$ARGV[0] ;
    print crypt($pw,$pw)."
    ";

    然后执行 chmod +x pwdgen.pl
    ./pwdgen.pl spring123
    spmBrZxsgt/pM
    spmBrZxsgt/pM 就是spring123的crypt()密码
    然后 将上面用 perl 生成的 加密后的密码
    按照
    用户名:密码
    的格式写到 pwd文件中

    密码文件生成好后,在 nginx.conf 文件中对应的 server 段中 添加如下红色的内容

    server {
            listen       99;
            ssi_types *;
            ssi_silent_errors off;
            server_name  localhost;
            auth_basic "Welcome to Kepler Admin!";
            auth_basic_user_file /root/password/pwd;
            location / {
                    ssi on;
                    root /root/kepler/admin-console;
            }
    
            location /api {
                    proxy_pass http://10.128.8.88:8080/kepler-collector-admin;
            }
         }

    如果想限制某一个目录的话需要如下配置:

    location ^~ /root/kepler/admin-console/ {
    auth_basic "TEST-Login!";
    auth_basic_user_file /root/password/pwd;
    }

    如果 不用 ^~ /root/kepler/admin-console/ 而用 /root/kepler/admin-console 的话 那么将只能对目录进行验证,如果直接访问其下的文件,将不会弹出登录验证

    重启Nginx服务,使配置生效

  • 相关阅读:
    Word+PS制作拼音表格
    VC6.0 突然打不开dsw 工程文件的解决方案
    C# 字符串的连接
    ASP.NET中弹出消息框的几种常见方法
    用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树
    WPF 显示模态窗口和窗体
    mysql5.5安装图解
    Microsoft Visual Studio 2010 Service Pack 1(exe)
    HTTP错误 404.17
    2014-2-7
  • 原文地址:https://www.cnblogs.com/longzhaoyu/p/4819519.html
Copyright © 2011-2022 走看看