Apache 反向代理 SSL 握手也失败 AH001897

Apache 反向代理 SSL 握手也失败 AH001897

这是我的设置:

  • Apache2 在 Ubuntu 18 上运行。
  • Certbot 正在运行以提供 SSL 证书
  • 两个 dotnet (kestrel) 应用程序正在监听 https://:5001 和 https://:5003
  • 这两个应用程序已使用与 Apache 服务器相同的证书绑定到其 SSL 端口,只不过已使用 OpenSSL 将其转换为 PFX 格式以合并密钥文件

端口 5003 上的应用程序需要安全连接才能启用用户身份验证。即使使用 Apache 的安全连接,此应用程序也无法通过不安全的端口正常工作。如果尝试登录,登录 cookie 基本上会丢失。

我尝试添加 SSLVerifyClient 和/或 SSLProxyVerify 来确认连接,但两者都不允许连接到任何一个应用程序。

每次我重新启动 Apache 时,都会收到 AH001897,它告诉我尽管 SSLCACertificateFile 指令指向 /etc/ssl/certs/ca-certificates.crt 中的捆绑包,但没有已知的 ca 证书。

Certbot 生成 fullchain.pem 作为证书文件。我已将其与 privkey.pem 组合以创建如上所述的 pfx 文件。我还复制并重命名了 fullchain.pem 为 https-le.crt,并将其放在 /usr/share/ca-certificates/dotnet/ 文件夹中,将其权限更改为 644,并使用 sudo dpkg-reconfigure ca-certificates 将其添加到受信任的证书中。这是正确的做法吗???

有人能指出我做错什么吗?

这是我的 Apache 配置文件的 ssl 部分:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName <mydomain>
    ServerAlias <mydomain>
    ProxyPreserveHost on

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/<mydomain>/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/<mydomain>/privkey.pem

SSLProxyEngine on
SSLCACertificateFile /etc/ssl/certs/ca-certificates.crt

    ProxyPass /gnomes https://127.0.1.1:5003/gnomes
    ProxyPassReverse /gnomes https://127.0.1.1:5003/gnomes

    ProxyPass / https://127.0.1.1:5001/
    ProxyPassReverse / https://127.0.1.1:5001/

    ErrorLog ${APACHE_LOG_DIR}mainsite-error.log
    CustomLog ${APACHE_LOG_DIR}mainsite-access.log common

</VirtualHost>
</IfModule>

根据建议,我已阅读下面建议的 Let's Encrypt 链接,并为 localhost 创建了一个自签名证书。然后,我将其添加到 ca-certificates 批量文件(受信任列表)中,并将代理重定向从 127.0.1.1 更改为 localhost。

以下是 SSLProcyVerify 设置为需要的日志条目。我注意到错误涉及端口 5001,但实际请求应该重定向到 5003,因为请求的 URL 是 mydomain/gnomes/?game=3

[Sat Jun 13 23:03:28.546026 2020] [ssl:error] [pid 23133:tid 139777085007616] [remote 127.0.0.1:5001] AH02039: Certificate Verification: Error (20): unable to get local issuer certificate
[Sat Jun 13 23:03:28.546211 2020] [proxy_http:error] [pid 23133:tid 139777085007616] (103)Software caused connection abort: [client 192.168.1.1:61303] AH01102: error reading status line from remote server localhost:5001, referer: https://<mydomain>/gnomes/?game=3
[Sat Jun 13 23:03:28.551816 2020] [ssl:error] [pid 23134:tid 139777051436800] [remote 127.0.0.1:5001] AH02039: Certificate Verification: Error (20): unable to get local issuer certificate
[Sat Jun 13 23:03:28.551936 2020] [proxy_http:error] [pid 23134:tid 139777051436800] (103)Software caused connection abort: [client 192.168.1.1:61304] AH01102: error reading status line from remote server localhost:5001, referer: https://<mydomain>/gnomes/?game=3
[Sat Jun 13 23:03:28.551969 2020] [proxy:error] [pid 23134:tid 139777051436800] [client 192.168.1.1:61304] AH00898: Error reading from remote server returned by /favicon.ico, referer: https://<mydomain>/gnomes/?game=3

不要忘记,每次重新启动 apache 时 AH001897 也会出现。

答案1

尽管以下内容并非严格意义上上述问题的答案,但我发布它是因为我的问题现已解决。

我发现我不需要 SSLProxyVerify 或 SSLVerifyClient,因为 SSL 配置足够安全,可以使两个应用程序正常工作。

我了解到,导致身份验证失败的不是 SSL 故障。实际问题是应用程序需要正确设置才能共享身份验证 cookie。

我的计划是让用户先登录主应用程序,然后重定向到第二个应用程序。我一直以这种方式进行测试,但失败了。我发现当我先登录第二个应用程序时,我无法登录第一个应用程序!

这在应用程序的代码中已得到解决,即指向一个通用的密钥文件并正确命名 cookie。

如果您是一名 dotnet 程序员并且想要了解更多信息,请参阅 StackOverflow 上发布的问题:

https://stackoverflow.com/questions/62273042/blazor-with-ssl-on-ubuntu-and-certbot/62379092#62379092

答案2

我遇到过类似的问题。然后我尝试通过将根证书放在顶部,然后分别将中间证书和服务器证书放在顶部来反转证书序列。它成功了。

相关内容