AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1158860
Accepted
raphael75
raphael75
Asked: 2024-05-03 22:05:02 +0800 CST2024-05-03 22:05:02 +0800 CST 2024-05-03 22:05:02 +0800 CST

尝试在 apache 中的别名目录上配置密码保护

  • 772

我的 Windows 服务器上有 apache 2.4.57。我新建了一个文件夹,只需要显示可以下载的文件。在 httpd.conf 文件中,我添加了以下内容:

Alias "/pw_files" "f:\www_shared\pw_files" 
<Directory "f:\www_shared\pw_files">
    Require all granted
    Options Indexes
    IndexOptions FancyIndexing HTMLTable FoldersFirst SuppressDescription SuppressLastModified NameWidth=* IconWidth=20 IconHeight=20
    IndexStyleSheet /css/autoindex.css
</Directory>

我在 f:\www_shared\pw_files 中创建了一个 .htpasswd 文件:

AuthType Basic
AuthName "please enter credentials"
AuthUserFile f:\www_shared\pw_files
AuthGroupFile "c:/apache_php/apache/htpasswd_group2.txt"
Require group pw_files

我创建了一个新用户:

htpasswd -c f:\www_shared\pw_files\.htpasswd pw_user

我将输出从 .htpasswd 移至 c:\apache_php\apache 中的 .htpasswd 文件

在 c:/apache_php/apache/htpasswd_group2.txt 我有:

pw_files: admin pw_user

我进行了这些更改并重新启动。

但是,当我去:

http://www.example.com/pw_files

我需要查看该文件夹的内容,但我从未收到输入用户名和密码的提示。我不确定我错过了什么。

apache-2.4
  • 1 1 个回答
  • 23 Views

1 个回答

  • Voted
  1. Best Answer
    HBruijn
    2024-05-03T22:17:56+08:002024-05-03T22:17:56+08:00

    最大的误解之一是 Apache 密码保护和 mod 重写规则必须放在.htaccess文件中。那是错误的。https://httpd.apache.org/docs/2.4/howto/htaccess.html#when

    您显然可以访问主要的 Apache 配置并且httpd.conf;那么建议将您的访问限制放在<Directory "f:\www_shared\pw_files">您已有的部分中。

    其次:您的f:\www_shared\pw_files似乎是一个目录,然后AuthUserFile f:\www_shared\pw_files是不正确的,因为AuthUserFile指令需要一个文件路径。代替使用AuthUserFile f:\www_shared\pw_files\.htpasswd。

    然后:.htaccess除非使用AllowOverride指令启用并且允许其中使用的指令类,否则文件将被忽略。

    最后:摆脱Require all granted基本上删除所有访问限制的指令:

    Alias "/pw_files" "f:\www_shared\pw_files" 
    <Directory "f:\www_shared\pw_files">
        Options Indexes
        IndexOptions FancyIndexing HTMLTable FoldersFirst SuppressDescription SuppressLastModified NameWidth=* IconWidth=20 IconHeight=20
        IndexStyleSheet /css/autoindex.css
        AuthType Basic
        AuthName "please enter credentials"
        AuthUserFile "f:/www_shared/pw_files/.htpasswd"
        AuthGroupFile "c:/apache_php/apache/htpasswd_group2.txt"
        Require group pw_files
    </Directory>
    
    • 1

相关问题

  • %{REQUEST_FILENAME}.ext 是什么意思?为什么额外的 .ext 结尾?

  • 为什么我的 Apache 能够提供 200 个包含斜杠的 .php 文件?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve