要使用验证码准备授权,我们需要
nginx本身及其插件
cryptod -session ,
form-input ,
ctpp2 ,
echo ,
ldap ,
headers-more ,
auth_request ,
set-misc 。 (我提供了到fork的链接,因为我做了一些尚未塞入原始存储库的更改。您还可以使用
现成的图像 。)
首先,让我们进行设置
encrypted_session_key "abcdefghijklmnopqrstuvwxyz123456";
接下来,以防万一,禁用授权标头
more_clear_input_headers Authorization;
现在我们通过授权保护一切
auth_request /auth; location =/auth { internal; subrequest_access_phase on;
对于授权用户,我们显示其文件夹中的内容
location / { alias html/$remote_user/; }
如果没有授权,我们会在验证码中显示验证码
error_page 401 = @error401; location @error401 { set_escape_uri $request_uri_escape $request_uri;
login.html
<html> <body> <form method="post"> <input type="hidden" name="csrf" value="<TMPL_var csrf>" /> username: <input type="text" name="username" placeholder="Enter User Name..." /><br /> password: <input type="password" name="password" /><br /> captcha: <img src="/captcha?csrf=<TMPL_var csrf>"/><input type="text" name="captcha" autocomplete="off" /><br /> <input type="submit" name="submit" value="submit" /> </form> </body> </html>