在基本身份验证中将 HTTP 重定向到 HTTPS 的关键作用是什么?

what is key role of redirection HTTP to HTTPS in basic authentication?

我在 ColdFusion 11 中工作,在 windows 托管中使用 apache 网络服务器 我对基本身份验证没有更多的了解,所以我对此有点困惑

  1. 为什么基本身份验证类型将密码存储在 .htpasswd 文件所以 不需要存储数据库?
  2. 如何在进入之前将请求HTTP重定向到https 密码 提示?

.htaccess 文件代码工作正常,首先完全验证,然后在 HTTP 上重定向到 https,但我想在此处输入密码之前将 HTTP 设置为 https 我的 httpd.config 文件虚拟主机代码

<VirtualHost  112.192.12.16>
    DocumentRoot C:/Apache24/htdocs/enovis53
    ServerName test.example.com
    ErrorLog logs/enovis-inc.com-error_log
    CustomLog logs/enovis-inc.com-access_log common
</VirtualHost>

我的.htaccess 文件代码

AuthName "Example CLMS Production (v5.3.0.0)"

AuthType Basic
AuthUserFile "C:\Apache24\htdocs\enovis53\.htpasswd"
require valid-user

如果有人知道这个然后指导我我不知道问社区所有建议都可以接受提前谢谢

  1. why does basic authentication type store password in .htpasswd file so not necessary to store database?

这是由AuthBasicProvider

决定的

Syntax: AuthBasicProvider provider-name [provider-name] ...
Default: AuthBasicProvider file

The AuthBasicProvider directive sets which provider is used to authenticate the users for this location. The default file provider is implemented by the mod_authn_file module.

所以在你的例子中,没有定义提供者,而是应用默认的(文件)。如果您想要其他提供商,例如一些数据库,指定 dbmldap、...


  1. how to redirect request HTTP to https before entering in password prompt?

通常,某些指令是无条件应用的,除非以某种方式受到限制。要仅在 HTTPS 处于活动状态时请求密码,您可以尝试将 Auth 指令或至少 Require 包含在 If

<If "%{HTTPS} == 'on'">
    AuthName "Example CLMS Production (v5.3.0.0)"
    AuthType Basic
    AuthUserFile "C:\Apache24\htdocs\enovis53\.htpasswd"
    require valid-user
</If>

但是现在,通过 http://test.example.com 请求时,无需密码即可访问所有内容。别忘了强制https!


无关,但请注意来自 AuthUserFile

的安全警告

Security

Make sure that the AuthUserFile is stored outside the document tree of the web-server. Do not put it in the directory that it protects. Otherwise, clients may be able to download the AuthUserFile.