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 / 问题 / 1044629
Accepted
Louis Sayers
Louis Sayers
Asked: 2020-12-02 20:29:54 +0800 CST2020-12-02 20:29:54 +0800 CST 2020-12-02 20:29:54 +0800 CST

在使用 GCP 负载均衡器配置 IAP 的情况下,如何从 HTTP 重定向到 HTTPS?

  • 772

我目前有一个托管在 Google Compute Engine 上的网站,该网站通过位于负载均衡器后面的 Identity-Aware-Proxy 进行了身份验证。这一切都适用于 https,但我想确保 http 重定向到 https,因为它目前只响应 404。

因此,我遵循了https://cloud.google.com/load-balancing/docs/https/setting-up-http-https-redirect,它告诉您设置第二个负载均衡器以将 http 流量重定向到 https。

但是,问题是,按照这些说明操作后,当我浏览到http://my-website.com时,我收到以下错误:

错误 403(禁止)!!1

  1. 那是一个错误。

您的客户端无权从此服务器获取 URL /。我们知道的就这些。

尽管 http 负载均衡器设置了 301 - 永久移动完整路径重定向,但在浏览器开发人员工具网络选项卡中没有发生重定向。它只是立即以 403 响应。URL 也使用 http:// 方案。


总而言之,我的设置如下所示:

外部 HTTPS 负载均衡器

  • 前端 - HTTPS、静态 IP、仅限 HTTPS
  • 后端 - Identity-Aware-Proxy(通过 Identity Platform 进行电子邮件身份验证)-> Compute Engine 实例组

外部 HTTP 负载均衡器

  • 前端 - HTTP,静态 IP(与上面的 HTTPS 负载均衡器相同)
  • 后端 - 无
  • 主机和路径规则:
    • 模式:高级主机和路径规则(URL 重定向、URL 重写)
    • 行动:将客户端重定向到不同的主机/路径
    • 主机重定向: https ://my-website.com
    • 路径值: *
    • 重定向响应代码: 301 - 永久移动
    • HTTPS 重定向:已启用

任何想法如何解决这个问题,而不是得到 403 将不胜感激!

http https http-status-code-403 google-cloud-http-load-balancer
  • 1 1 个回答
  • 982 Views

1 个回答

  • Voted
  1. Best Answer
    Wojtek_B
    2020-12-03T04:35:08+08:002020-12-03T04:35:08+08:00

    您描述的方式看起来像是 url-map 有问题,因为您可以访问http您网站的版本。

    绝对确定使用命令仔细检查(或创建新的)url-map gcloud:

    gcloud compute url-maps describe web-map-http
    
    creationTimestamp: '2020-12-02T03:18:27.053-08:00'
    defaultUrlRedirect:
      httpsRedirect: true
      redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
    fingerprint: KU2hPu1ao=
    id: '50586028237895404'
    kind: compute#urlMap
    name: web-map-http
    selfLink: https://www.googleapis.com/compute/v1/projects/xxxxx/global/urlMaps/web-map-http
    

    准备好 URL 映射后,创建一个目标代理:

    gcloud compute target-http-proxies create http-lb-proxy \
       --url-map=web-map-http \
       --global
    

    结果:

    gcloud compute target-http-proxies describe http-lb-proxy
    creationTimestamp: '2020-12-02T03:19:39.090-08:00'
    fingerprint: lgJkIY8E=
    id: '3781119498457764'
    kind: compute#targetHttpProxy
    name: http-lb-proxy
    selfLink: https://www.googleapis.com/compute/v1/projects/xxxx/global/targetHttpProxies/http-lb-proxy
    urlMap: https://www.googleapis.com/compute/v1/projects/xxxx/global/urlMaps/web-map-http
    

    和转发规则:

    gcloud compute forwarding-rules create http-content-rule \
       --address=lb-ipv4-1 \ # Same IP address used for HTTPS load balancer
       --global \
       --target-http-proxy=http-lb-proxy \
       --ports=80
    

    wchich 应该看起来像:

    gcloud compute forwarding-rules describe http-content-rule --global
    IPAddress: 34.107.123.141
    IPProtocol: TCP
    creationTimestamp: '2020-12-02T03:22:38.132-08:00'
    description: ''
    fingerprint: L1vA0Ik9Y=
    id: '888330202637841'
    kind: compute#forwardingRule
    loadBalancingScheme: EXTERNAL
    name: http-content-rule
    networkTier: PREMIUM
    portRange: 80-80
    selfLink: https://www.googleapis.com/compute/v1/projects/xxxx/global/forwardingRules/http-content-rule
    target: https://www.googleapis.com/compute/v1/projects/xxxx/global/targetHttpProxies/http-lb-proxy
    

    确保为 HTTP 和 HTTPS LB 使用相同的公共 IP。如果传入流量没有被阻止,请检查防火墙规则。

    如果你做的一切都是正确的,你应该得到与curl示例中相同的输出。

    • 1

相关问题

  • 设置 http 代理以使用 Web 界面?

  • 无法连接到 Ubuntu Desktop 中的端口 80 或 VMWare Workstation 6.52 中的 Server 9.04

  • IIS 7.5 (Windows 7) - HTTP 错误 401.3 - 未经授权

  • 为什么有些网站的网址中没有“www”就无法显示?[关闭]

  • Tomcat 6 HTTP 日志滚动和清除

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