美文网首页
h5ai使用nginx加密目录配置

h5ai使用nginx加密目录配置

作者: JC_Wang | 来源:发表于2017-12-30 01:19 被阅读978次

    1 不可行方案,只能全局加密,不能目录

    • 只是在index.php做判断,然后显示输入密码 (目录在 _h5ai/public/index.php)
    <?php
    $lifeTime = 60; //设置密码过期时间
    session_set_cookie_params($lifeTime);
    session_start();
    if(isset($_POST['password']) && $_POST['password'] == 'siji'){
        $_SESSION['ok'] = 1;
        header('location:?');
    }
    if(!isset($_SESSION['ok'])){
        exit('
           <html>
           <head>
           <meta name="viewport" content="width=device-width, initial-scale=1" />
           <link rel="stylesheet" href="/_h5ai/public/css/styles.css">
           </head>
           <body class="info" id="root">
           <div style="height:100px; line-height:100px;" align="center" valign="center">
           </div>
           <div id="login-wrapper" style="height:100px; line-height:40px;" align="center" valign="center">
           <img src="https://oclog.pw/doc/zq.jpg"/ width="280px" height="280px"> 
           <h2 id="header"class="h1" >
              输入密码
           </h2>
           <form method="post" class="form" >
                <input id="pass" name="password"/>
                <input type="submit" id="login" value ="确认" style="border:none;background:#42a5f5"/>
            </form>
            </div>
            </body>
           </html>
        ');
    }
    ?>
    
    QQ截图20171230011021.png

    2、可行方案,通过nginx认证

    参考网址 nginx 官方加密教程

    在网站对应的conf中配置如下 (/www/server/panel/vhost/nginx)

    #禁止访问的文件或目录
        location ~ ^/(\.user.ini|\.htaccess|\.git|\.project|LICENSE|README.md)
        {
            return 404;
        }
        
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
            access_log off; 
        }
        
        location ~ .*\.(js|css)?$
        {
            expires      12h;
            access_log off; 
        }
    ---------------------------------------------------------------------------------
        location ~ /secret_h {
        auth_basic           "root";
        auth_basic_user_file /www/wwwroot/htpasswd;
        }
    ------------------------------------------------------------------------------
    
    QQ截图20171230012859.png

    2、剩下的,老司机们自己想象。。。。

    相关文章

      网友评论

          本文标题:h5ai使用nginx加密目录配置

          本文链接:https://www.haomeiwen.com/subject/rgfggxtx.html