我正在尝试使用构建代理 HTTP 授权页面mod_auth_form
我的目标是在目录中有一个 Auth 页面DocumentRoot
,然后一旦用户连接,只需代理所有路由到“真实”应用程序,在 localhost 上使用另一个端口运行。
我在根目录下使用 Auth 指令设置了我的虚拟主机Location
:
<VirtualHost *:80>
ServerName subdomain.example.com
DocumentRoot /var/www/subdomain.example.com/web/
<Location /login.html>
Order allow,deny
Allow from all
</Location>
<Location />
SetHandler form-login-handler
AuthType Form
AuthName realm
AuthFormProvider file
AuthUserFile /var/www/subdomain.example.com/.htpasswd
AuthFormLoginRequiredLocation "http://subdomain.example.com/login.html"
require valid-user
Session On
SessionCookieName session path=/
SessionCryptoPassphrase any-secret-passphrase
</Location>
ProxyPass /login.html !
ProxyPassReverse /login.html !
ProxyPass / http://localhost:8888
ProxyPassReverse / http://localhost:8888
ErrorLog ${APACHE_LOG_DIR}/subdomain.example.com/error.log
CustomLog ${APACHE_LOG_DIR}/subdomain.example.com/access.log combined
</VirtualHost>
编辑
我需要的只是颠倒<Location></Location>
指令的顺序......并为表单处理程序添加一个特殊的位置。工作解决方案:
<VirtualHost *:80>
ServerName subdomain.example.com
DocumentRoot /var/www/subdomain.example.com/web/
<Location />
AuthType Form
AuthName realm
AuthFormProvider file
AuthUserFile /var/www/subdomain.example.com/.htpasswd
AuthFormLoginRequiredLocation "http://subdomain.example.com/login.html"
AuthFormLoginSuccessLocation "http://subdomain.example.com/"
require valid-user
Session On
SessionCookieName session path=/
SessionCryptoPassphrase any-secret-passphrase
</Location>
<Location /login_check.html>
SetHandler form-login-handler
AuthType Form
AuthName realm
AuthFormProvider file
AuthUserFile /var/www/subdomain.example.com/.htpasswd
AuthFormLoginRequiredLocation "http://subdomain.example.com/login.html"
AuthFormLoginSuccessLocation "http://subdomain.example.com/"
require valid-user
Session On
SessionCookieName session path=/
SessionCryptoPassphrase any-secret-passphrase
</Location>
<Location /login.html>
Order allow,deny
Allow from all
</Location>
ProxyPreserveHost On
ProxyPass /login.html !
ProxyPassReverse /login.html !
ProxyPass / http://localhost:8888
ProxyPassReverse / http://localhost:8888
ErrorLog ${APACHE_LOG_DIR}/subdomain.example.com/error.log
CustomLog ${APACHE_LOG_DIR}/subdomain.example.com/access.log combined
</VirtualHost>
当我尝试访问 subdomain.example.com 时,我被重定向到 subdomain.example.com/login.html(这很好!)
此 /var/www/subdomain.example.com/web/login.html 页面的内容:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta name='viewport' content='width=device-width' />
<title>Authentication</title>
</head>
<body>
<form method='POST' action='/login_check.html'>
<div class='form-group'>
<label for='httpd_username'>Username</label>
<input id='http_username' class='form-control' type='text' name='httpd_username' value='' />
</div>
<div class='form-group'>
<label for='httpd_password'>Password</label>
<input id='httpd_password' class='form-control' type='password' name='httpd_password' value='' />
</div>
<div class='form-group'>
<input class='btn btn-success' type='submit' name='login' value='Login' />
</div>
</form>
</body>
</html>
但是,这个 login.html 页面永远不会显示,我收到一个TOO_MANY_REDIRECTS
错误:
http://subdomain.example.com/login.html的网页导致了过多的重定向。
似乎这条特殊路线必须被 Auth 进程“锁定”......但我不知道如何启用它......
我试图添加另一个ErrorDocument 401 /login.html
指令,但它没有改变任何东西。