apache - 从负载均衡器到后端的加密无法使用 HTTPS 后端进行
问题描述
我在 GCP 中创建了一个负载均衡器,用于使用 HTTPS 将其转发到 HTTPS 后端组。我已通过在实例上创建证书将实例配置为使用 HTTPS,当我从实例本身卷曲时,我得到以下信息
curl https://localhost
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
root@instance:/var/log/apache2# curl https://localhost -k
<WebPage content>
我检查了有关从负载均衡器到后端的加密的 GCP 文档,并按照说明配置了后端和运行状况检查。
但是,健康检查显示 UNHEALTHY,并且健康检查日志显示
healthCheckProbeResult: {
connectLatency: "0.000651s"
detailedHealthState: "TIMEOUT"
healthCheckProtocol: "HTTPS"
healthState: "UNHEALTHY"
ipAddress: "10.8.1.4"
previousDetailedHealthState: "UNKNOWN"
previousHealthState: "UNHEALTHY"
probeCompletionTimestamp: "2021-08-11T07:46:06.973978919Z"
probeRequest: "/user"
probeResultText: "HTTP response: , Error: Protocol error"
probeSourceIp: "35.191.1.154"
responseLatency: "0.002054s"
targetIp: "<internal IP>"
targetPort: 443
}
当我只使用 HTTP 时,通过更改 apache 和后端配置,该站点可以正常工作。
我无法调试这里的实际问题。
我希望在负载均衡器和后端之间进行加密。因此,任何其他方法都将受到欢迎。
解决方案
健康检查错误是TIMEOUT。这意味着您的后端确实接受了端口 443 上的连接。
你的问题没有详细说明 Apache/Nginx 是怎样的?已配置。
检查您是否在 Web 服务器中配置了端口 443 侦听器。
检查您是否为端口 443 启用了 VPC 防火墙规则。
默认 VPC 防火墙规则default-all-https允许端口 443 上的流量。您可以选择将名为https-server的网络标签应用于VM 实例。
如果后端 Web 服务正在运行并侦听端口 443,则以下命令将为 HTTPS 端口 443 启用默认防火墙规则。
将https-server网络标签应用到 Compute Engine 虚拟机实例:
gcloud compute instances add-tags [INSTANCE_NAME] \
--zone [INSTANCE_ZONE] \
--tags="https-server"
列出您的 Compute Engine 虚拟机实例并查看标签:
gcloud compute instances list --format="table(name,status,tags.list())"
注意:以上步骤有利于调试。但是,这将允许整个 Internet 连接到您的后端。更好的解决方案是创建一个防火墙规则,只允许来自负载均衡器和健康检查服务的流量。允许的地址是:
- 130.211.0.0/22
- 35.191.0.0/16
以下命令将创建一个 VPC 防火墙规则,允许所有实例接收来自 Google Cloud 负载均衡器和运行状况检查服务的流量。可以微调此规则以分配给特定实例:
gcloud compute firewall-rules create "lb-rule" --allow=tcp:80,tcp:443 \
--source-ranges="10.0.0.0/22,10.0.0.0/14" \
--source-ranges="130.211.0.0/22,35.191.0.0/16" \
--description="Allow traffic from load balancer and health check services"
推荐阅读
- sql - 将调试脚本添加到存储过程中
- javascript - 如何将 axios.get 多个响应结果包装到一个数组中?
- javascript - 如果元素不存在,为什么 instanceof HTMLElement 返回 false?
- c# - 单实例 [Windows 必须在处理单实例时重新打开......]
- python - 在上面的代码中判断一个数是否为素数
- c# - 如何检查/查找变换下存在的游戏对象是隐藏的还是活动的?
- python - Python 'object() 没有参数' 错误
- postgresql - 如何在 postgresql 中使用 jsonb_set 更新一个空的 jsonb 列?
- java - 我不明白为什么我是假的,而不是真的,请查看代码并帮助我
- node.js - 需要在 docker node:alpine image 中使用 wkhtmltopdf