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
    • 最新
    • 标签
主页 / computer / 问题 / 1446728
Accepted
Darren
Darren
Asked: 2019-06-10 09:57:09 +0800 CST2019-06-10 09:57:09 +0800 CST 2019-06-10 09:57:09 +0800 CST

是什么导致此 Apache 401 错误?

  • 772

我在 Debian 9.9 上安装了 Apache 2.4,除了提供一个 Roundcube 实例(目前是 1.4 RC-1)之外,基本上什么都不做。

Apache的文档根目录是/home/web(因为原因),Roundcube实例安装在/home/web/mail.

Apache 用户 ( www-data) 具有对整个/home/web目录树的完全读/写访问权限。

文档根目录有一个重定向到的索引文件,www.mydomain.co.uk/mail我用mod_rewrite它来将任何 HTTP 请求更改为 HTTPS。

今天我注意到(并且不知道它发生了多久)当我点击mydomain.co.uk它时在 Apache 中记录了一个 401 错误:

192.168.10.79 - - [09/Jun/2019:18:49:59 +0100] "GET /mail/ HTTP/1.1" 401 2955 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0)
Gecko/20100101 Firefox/67.0"

当从外部访问它时,这尤其是一个问题,因为它会触发 fail2ban 规则并禁止我的客户。

401 错误表示“身份验证失败”,但我尚未使用 Apache 在该目录上设置任何身份验证,AIUI 需要存在一个.htpasswd文件 - 我已经检查了我的 Apache 文档根目录中是否存在该文件,但没有- 或者在虚拟主机文件中使用 auth 子句 - 其中也没有。

如何找到原因并防止出现此 401 错误?

来自 Fiddler 的一些调试信息:

GET https://www.mydomain.co.uk/mail/ HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: www.mydomain.co.uk
Connection: Keep-Alive
Cookie: roundcube_sessid=sadh0s1j2rn769rvebhpsv6m81

HTTP/1.0 401 Unauthorized
Date: Mon, 10 Jun 2019 08:27:28 GMT
Server: Apache/2.4.25 (Debian)
Strict-Transport-Security: max-age=63072000; includeSubdomains;
Expires: Mon, 10 Jun 2019 08:27:28 GMT
Cache-Control: private, must-revalidate
Pragma: private
Last-Modified: Mon, 10 Jun 2019 08:27:28 GMT
X-UA-Compatible: IE=edge
X-Frame-Options: sameorigin
Content-Language: en
Vary: Accept-Encoding
X-Robots-Tag: noindex, nofollow
Connection: close
Content-Type: text/html; charset=UTF-8
Content-Length: 5435

如果我在“Auth”选项卡下查看 Fiddler:

No Proxy-Authenticate Header is present.

No WWW-Authenticate Header is present.

来自 wget 的一些进一步的 degug 信息:

DEBUG output created by Wget 1.18 on linux-gnueabi.

Reading HSTS entries from /home/darren/.wget-hsts
URI encoding = ‘UTF-8’
Converted file name 'mail' (UTF-8) -> 'mail' (UTF-8)
--2019-06-10 13:34:43--  https://www.mydomain.co.uk/mail
Certificates loaded: 151
Resolving www.mydomain.co.uk (www.mydomain.co.uk)... XX.XX.XX.XX
Caching www.mydomain.co.uk => XX.XX.XX.XX
Connecting to www.mydomain.co.uk (www.mydomain.co.uk)|XX.XX.XX.XX|:443... connected.
Created socket 3.
Releasing 0x004bf2e0 (new refcount 1).

---request begin---
GET /mail HTTP/1.1
User-Agent: Wget/1.18 (linux-gnueabi)
Accept: */*
Accept-Encoding: identity
Host: www.mydomain.co.uk
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 301 Moved Permanently
Date: Mon, 10 Jun 2019 12:34:43 GMT
Server: Apache/2.4.25 (Debian)
Strict-Transport-Security: max-age=63072000; includeSubdomains;
Location: https://www.mydomain.co.uk/mail/
Content-Length: 331
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

---response end---
301 Moved Permanently
Registered socket 3 for persistent reuse.
Parsed Strict-Transport-Security max-age = 63072000, includeSubDomains = true
Added new HSTS host: www.mydomain.co.uk:443 (max-age: 63072000, includeSubdomains: true)
URI content encoding = ‘iso-8859-1’
Location: https://www.mydomain.co.uk/mail/ [following]
Skipping 331 bytes of body: [<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a hreSkipping 157 bytes of body: [f="https://www.mydomain.co.uk/mail/">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at www.mydomain.co.uk Port 443</address>
</body></html>
] done.
URI content encoding = None
Converted file name 'mail' (UTF-8) -> 'mail' (UTF-8)
--2019-06-10 13:34:43--  https://www.mydomain.co.uk/mail/
Reusing existing connection to www.mydomain.co.uk:443.
Reusing fd 3.

---request begin---
GET /mail/ HTTP/1.1
User-Agent: Wget/1.18 (linux-gnueabi)
Accept: */*
Accept-Encoding: identity
Host: www.mydomain.co.uk
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.0 401 Unauthorized
Date: Mon, 10 Jun 2019 12:34:43 GMT
Server: Apache/2.4.25 (Debian)
Strict-Transport-Security: max-age=63072000; includeSubdomains;
Set-Cookie: roundcube_sessid=9dd09n33d6k3f1kil69f90bkk6; path=/; secure; HttpOnly
Expires: Mon, 10 Jun 2019 12:34:43 GMT
Cache-Control: private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Last-Modified: Mon, 10 Jun 2019 12:34:43 GMT
X-Frame-Options: sameorigin
Content-Language: en
Vary: Accept-Encoding
X-Robots-Tag: noindex, nofollow
Connection: close
Content-Type: text/html; charset=UTF-8

---response end---
401 Unauthorized

Stored cookie www.mydomain.co.uk -1 (ANY) / <session> <secure> [expiry none] roundcube_sessid 9dd09n33d6k3f1kil69f90bkk6
Disabling further reuse of socket 3.

Username/Password Authentication Failed.
Saving HSTS entries to /home/darren/.wget-hsts
apache-http-server roundcube
  • 2 2 个回答
  • 5181 Views

2 个回答

  • Voted
  1. harrymc
    2019-06-10T12:34:22+08:002019-06-10T12:34:22+08:00

    401 Unauthorized Error 是一个 HTTP 响应状态代码,表示客户端发送的请求无法通过身份验证,但可能有多种原因。

    我会建议:

    • 发布完整的请求和响应文本供我们检查。特别感兴趣的是WWW-Authenticate响应标头,它包含一个或多个挑战字符串,每个字符串指示如何获得正确的身份验证以访问所请求的资源。

    • 检查 Apache 服务器日志(可能需要启用详细日志记录)。

    • 如果客户端被禁止,错误代码通常是 401。

    • 清除客户端浏览器上的所有 cookie 和浏览器缓存。

    • 使用禁用所有扩展程序的浏览器。在 Firefox 中这是安全模式,在 Chrome 中是隐身模式。

    • 如果您的应用程序设置为返回此错误代码,请在服务器上搜索。

    • 1
  2. Best Answer
    Darren
    2019-06-14T00:23:24+08:002019-06-14T00:23:24+08:00

    这是 Roundcube 中的一个新“特性”。

    当用户未登录时,我们返回 401。代码在 index.php 中,可以通过插件修改。

    资源

    这些是 Roundcube index.php 中有问题的行:

        $plugin = $RCMAIL->plugins->exec_hook('unauthenticated', array(
                'task'      => 'login',
                'error'     => $session_error,
                'http_code' => !$session_error ? 401 : 200
        ));
    
        $RCMAIL->set_task($plugin['task']);
    
    //    if ($plugin['http_code'] == 401) {
    //        header('HTTP/1.0 401 Unauthorized');
    //    }
    

    我已经注释掉最后三行以阻止产生 401 错误。

    • 1

相关问题

  • Apache 到 Nginx mod_rewrite 规则

  • 无法在本地主机中打开项目文件夹

  • Apache 两次发送 POST 请求

  • 是否可以将 Apache 配置为同一端口上的静态 Web 服务器和负载平衡器?

  • apache2 可以在没有 conf 文件的情况下工作吗?

Sidebar

Stats

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

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve