在我看来,我有一个根本的误解,“mod_auth_form”应该如何工作。我参考了Apache文档的这个页面:
http://httpd.apache.org/docs/current/mod/mod_auth_form.html
我有一个公用文件夹和一个私人文件夹
我想要实现的是文件夹被锁定。用户需要使用他们的用户名和密码登录才能看到我的受保护文件夹的index.php页面。
这是我的虚拟主机设置:
<VirtualHost *:80>
ServerName customform.uwe
DocumentRoot "/home/uwe/www/protected_custom_form"
DirectoryIndex index.php
ErrorLog /var/log/apache2/protected_custom_form.error.log
CustomLog /var/log/apache2/protected_custom_form.access.log combined
<Directory "/home/uwe/www/protected_custom_form">
AllowOverride All
Allow from All
</Directory>
<Directory "/home/uwe/www/protected_custom_form/secret/">
</Directory>
<Location /dologin>
SetHandler form-login-handler
AuthFormLoginRequiredLocation http://customform.uwe/login.html
AuthFormProvider file
AuthUserFile /home/uwe/www/conf/passwd
AuthType form
AuthName realm
Session On
SessionCookieName session path=/
SessionCryptoPassphrase secret
</Location>
</VirtualHost>
这是我的登录表单,它位于我的虚拟服务器的公共文件夹中:
<form method="POST" action="/dologin">
Username: <input type="text" name="httpd_username" value="" />
Password: <input type="password" name="httpd_password" value="" />
<input type="submit" name="login" value="Login" />
<input type="hidden" name="httpd_location" value="http://customform.uwe/secret/index.php" />
</form>
好的,这是发生的事情
这是我的问题:
此刻我正在撞墙,所以非常感谢你的帮助。
好的,我相信我现在已经整理好了。我一定有点困惑: - )
我遵循的想法包括两件事:
要实现这一点,我需要编辑两个文件:
这是虚拟主机:
<VirtualHost *:80>
ServerName customform.uwe
DocumentRoot "/home/uwe/www/protected_custom_form"
DirectoryIndex index.php
ErrorLog /var/log/apache2/protected_custom_form.error.log
CustomLog /var/log/apache2/protected_custom_form.access.log combined
#This is the public
<Directory "/home/uwe/www/protected_custom_form">
AllowOverride All
Allow from All
</Directory>
#This is the login handler, the login form needs to pint to this handler in its action!
<Location /dologin>
SetHandler form-login-handler
AuthFormLoginRequiredLocation http://customform.uwe/login.html
AuthFormLoginSuccessLocation http://customform.uwe/secret/secretindex.php
AuthFormProvider file
AuthUserFile /home/uwe/www/conf/passwd
AuthType form
AuthName realm
Session On
SessionCookieName session path=/
SessionCryptoPassphrase secret
</Location>
# This is the location setting I missed earlier: When a
# user comes to this location unauthorised, he will be redirect to the login form
# This happens as the ErrorDoucment gets overwritten with login page
<Location /secret/index.php>
Require valid-user
AuthFormProvider file
ErrorDocument 401 /login.html
AuthUserFile /home/uwe/www/conf/passwd
AuthType form
AuthName realm
AuthFormLoginRequiredLocation http://customform.uwe/login.html
Session On
SessionCookieName session path=/
SessionCryptoPassphrase secret
</Location>
</VirtualHost>
这是登录表单html 这里的变化是表单的动作处理程序现在指向我的位置 我在上面定义了
<form method="POST" action="/dologin">
Username: <input type="text" name="httpd_username" value="" />
Password: <input type="password" name="httpd_password" value="" />
<input type="submit" name="login" value="Login" />
<input type="hidden" name="httpd_location" value="/secret/secretindex.php" />
</form>
这似乎有效,它在Apache文档中全部(或多或少),但我感到困惑,因为它们没有完整的例子