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 / 问题 / 127708
Accepted
Jader Dias
Jader Dias
Asked: 2010-03-31 06:50:24 +0800 CST2010-03-31 06:50:24 +0800 CST 2010-03-31 06:50:24 +0800 CST

如何在 Apache httpd 虚拟主机中配置基本身份验证?

  • 772

我正在尝试使用 Apache http 配置 mercurial 访问。它需要身份验证。我的/etc/apache2/sites-enabled/mercurial样子是这样的:

NameVirtualHost *:8080

<VirtualHost *:8080>
    UseCanonicalName Off
    ServerAdmin  webmaster@localhost
    AddHandler cgi-script .cgi
    ScriptAliasMatch ^(.*) /usr/lib/cgi-bin/hgwebdir.cgi/$1
</VirtualHost>

我在互联网上阅读的每个教程都告诉我插入这些行:

AuthType Basic
AuthUserFile /usr/local/etc/httpd/users

但是当我这样做时,我收到以下错误:

# /etc/init.d/apache2 reload
Syntax error on line 8 of /etc/apache2/sites-enabled/mercurial:
AuthType not allowed here

我的发行版是一个定制的 Ubuntu,称为 Turnkey Linux Redmine

apache-2.2 authentication mercurial httpd http-authentication
  • 6 6 个回答
  • 171799 Views

6 个回答

  • Voted
  1. Best Answer
    Lanselot
    2010-03-31T07:33:45+08:002010-03-31T07:33:45+08:00

    你应该把它放在一个 Location 指令中:

    <VirtualHost *:8080>
    
    <Location /> #the / has to be there, otherwise Apache startup fails
                Deny from all
                #Allow from (You may set IP here / to access without password)
                AuthUserFile /usr/local/etc/httpd/users
                AuthName authorization
                AuthType Basic
                Satisfy Any # (or all, if IPs specified and require IP + pass)
                            # any means neither ip nor pass
                require valid-user
    </Location>
    ...
    </VirtualHost>
    
    • 83
  2. SLL
    2011-05-25T09:31:15+08:002011-05-25T09:31:15+08:00

    我在 ubuntu 10.04 上运行 Apache2——同样的问题,感谢您的解决方案。我发现我必须将配置放入/etc/apache2/apache2.conf

    您可以使用 htpasswd 生成用户名和密码。新文件:

    $ htpasswd -c /srv/auth/.htpasswd squire
    

    要附加到现有文件:

    $ htpasswd -b /srv/auth/.htpasswd squire2 tickleme2
    
    • 11
  3. Dan Andreatta
    2010-03-31T07:35:47+08:002010-03-31T07:35:47+08:00

    您可以保护位置或目录。对于目录添加如下内容:

    <Directory /some/dir/cgi-bin/>
        Options +ExecCGI
        AddHandler cgi-script .cgi
        AuthType Basic
        AuthName 'Private scripts'
        AuthUserFile '/some/other/dir/.htpasswd'
        Require valid-user
    </Directory>
    

    您还可以添加Deny和Allow指令以获得更精细的控制。

    • 8
  4. Warner
    2010-03-31T07:27:52+08:002010-03-31T07:27:52+08:00

    听起来您在VirtualHost. 通常,这些设置在Directory指令下指定。

    您也可以使用.htaccesss文件,但在 Apache conf 中指定是一个很好的默认值,因为它的暴露较少。

    阿帕奇文档

    • 4
  5. Alex Beynenson
    2011-02-15T18:19:27+08:002011-02-15T18:19:27+08:00

    我在 ubuntu 10.10 上运行 Apache2。我对上述所有解决方案都遇到了问题,但是效果很好(来自 apache docs):

    <目录/var/www/>
      选项索引 FollowSymLinks MultiViews
      允许覆盖所有
      命令允许,拒绝
      允许所有人
      AuthType 基本
      AuthName“受限”
      AuthBasicProvider 文件
      AuthUserFile /etc/users
      需要用户访问者
    </目录>
    

    与上述答案的最大区别似乎是 AuthBasicProvider 指令设置为“file”,而 Require 指令包括实际用户名之前的“user”位。

    希望这可以帮助某人。

    • 3
  6. DaveSB
    2012-01-07T04:31:52+08:002012-01-07T04:31:52+08:00

    我们在运行内存优化版的apache,遇到了这个问题。

    这是由于 apache 配置中不存在以下行:

    LoadModule authz_user_module modules/mod_authz_user.so
    
    • 3

相关问题

  • 在您分发的应用程序中使用 Apache HTTPD 运行 SSL 的最佳方式是什么?

  • 阿帕奇的替代品

  • 如何强制我的网址始终以 www 开头?

  • 在 Linux Xen VPS 上优化 Apache 和 MySQL

  • mod_rewrite 不转发 GET 参数

Sidebar

Stats

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

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

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

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

    • 9 个回答
  • Marko Smith

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

    • 3 个回答
  • Marko Smith

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

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +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