Die HTTPS-Umleitung des Cloud Load Balancing funktioniert für einen bestimmten Host nicht

Die HTTPS-Umleitung des Cloud Load Balancing funktioniert für einen bestimmten Host nicht

In meinem Load Balancer habe ich 6 Hosts, bei allen Hosts außer einem funktioniert die HTTPS-Umleitung einwandfrei. Ich habe jede mögliche Konfiguration ausprobiert und alle von Google bereitgestellten Dokumente gelesen (Konzepte, Anleitungen, Referenzen), wiehttps://cloud.google.com/load-balancing/docs/https/setting-up-http-https-redirect#setting_up_the_http_load_balancerumsonst...

Was mich verrückt macht, ist, dass es im selben url-mapHost einen Host gibt, dessen HTTPS-Umleitung zu 100 % funktioniert, der eine „identische“ Kopie des Hosts ist, der nicht funktioniert. Dies ist meins url-mapmit den beiden isolierten Hosts:

defaultUrlRedirect:
  httpsRedirect: true
  redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
  stripQuery: false

hostRules:
 - hosts:
   # I'm not using an actual record for this particular host, the following two are real
 - app.rocketseat.dev
  pathMatcher: path-matcher-staging
 - hosts:
 - app.rocketseat.com.br
  pathMatcher: path-matcher-production
 - hosts:
 - umbriel.rocketseat.dev
  pathMatcher: path-matcher-umbriel


pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client-staging
  name: path-matcher-staging
  pathRules:
  - paths:
    - /api/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendServices/app-staging
  - paths:
    - /*
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client-staging
  - paths:
    - /admin
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /index.html
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/admin-client-staging
  - paths:
    - /admin/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/admin-client-staging
  - paths:
    - /h
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /index.html
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/hubble-client-staging
  - paths:
    - /h/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/hubble-client-staging
  - paths:
    - /favicon.ico
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /favicon.png
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client-staging


- defaultService: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client
  name: path-matcher-production
  pathRules:
  - paths:
    - /api/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendServices/app
  - paths:
    - /*
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client
  - paths:
    - /admin
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /index.html
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/admin-client
  - paths:
    - /admin/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/admin-client
  - paths:
    - /h
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /index.html
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/hubble-client
  - paths:
    - /h/*
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/hubble-client
  - paths:
    - /favicon.ico
    routeAction:
      urlRewrite:
        pathPrefixRewrite: /favicon.png
    service: https://www.googleapis.com/compute/v1/projects/my-project-id/global/backendBuckets/student-client

http://app.rocketseat.dev/api/hellokehrt zurück:

{
  "jsonPayload": {
    "@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
    "statusDetails": "response_sent_by_backend"
  },
  "resource": {
    "type": "http_load_balancer",
    "labels": {
      "backend_service_name": "app-staging",
      "forwarding_rule_name": "app-forwarding-rule-2",
      "target_proxy_name": "app-target-https-proxy",
      "url_map_name": "app-url-map"
    }
  },
  "severity": "INFO"
}

http://app.rocketseat.com.br/api/hellokehrt zurück

{
  "jsonPayload": {
    "@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
    "statusDetails": "response_sent_by_backend"
  },
  "resource": {
    "type": "http_load_balancer",
    "labels": {
      "backend_service_name": "app",
      "forwarding_rule_name": "app-forwarding-rule",
      "target_proxy_name": "app-target-http-proxy",
      "url_map_name": "app-url-map"
    }
  },
  "severity": "INFO"
}

Ich dachte, es könnte vielleicht einen Unterschied bei der Konfiguration des Backend-Dienstes/Buckets geben, aber sie sind auch identisch.


Zusätzliche Ausgabe:

# gcloud compute url-maps describe app-http-url-map

defaultUrlRedirect:
  httpsRedirect: true
  redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
kind: compute#urlMap
name: app-http-url-map
selfLink: https://www.googleapis.com/compute/v1/projects/my-project-id/global/urlMaps/app-http-url-map

---
# gcloud compute target-http-proxies describe app-target-http-proxy

kind: compute#targetHttpProxy
name: app-target-http-proxy
selfLink: https://www.googleapis.com/compute/v1/projects/my-project-id/global/targetHttpProxies/app-target-http-proxy
urlMap: https://www.googleapis.com/compute/v1/projects/my-project-id/global/urlMaps/app-url-map

---
# gcloud compute target-https-proxies describe app-target-https-proxy

kind: compute#targetHttpsProxy
name: app-target-https-proxy
quicOverride: NONE
selfLink: https://www.googleapis.com/compute/v1/projects/my-project-id/global/targetHttpsProxies/app-target-https-proxy
sslCertificates:
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/xesque
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/europa
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/umbriel
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/flexbalancer
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/dev
- https://www.googleapis.com/compute/v1/projects/my-project-id/global/sslCertificates/app
urlMap: https://www.googleapis.com/compute/v1/projects/my-project-id/global/urlMaps/app-url-map

Antwort1

Basierend auf den Informationen, die Sie freundlicherweise bereitgestellt haben, und in ähnlichen Szenarien könnte es sein, dass Sie eine URL-Zuordnung für die HTTP-zu-HTTPS-Umleitung konfiguriert haben. Sie müssen jedoch eine HTTP-URL-Zuordnung erstellen, deren einziger Zweck darin besteht, den Datenverkehr auf die HTTPS-URL-Zuordnung umzuleiten, in der Sie die HostRules und PathMatchers konfigurieren.

In diesemBeispiel, „web-map-http“ wird ausschließlich erstellt, um HTTP-Verkehr auf die HTTPS-URL-Map „web-map-https“ umzuleiten, und „web-map-https“ ist der Ort, an dem Sie die HostRules und PathMatchers konfigurieren.

Die Cloud Console sollte zwei Load Balancer anzeigen

Das Erstellen einer URL-Zuordnung für die HTTP-zu-HTTPS-Umleitung und Host-Regeln könnte funktionieren, es handelt sich jedoch nicht um die empfohlene Vorgehensweise.

Antwort2

Am Ende wurde mir klar, dass das Problem nicht beim Host selbst lag, sondern dass die HTTPS-Weiterleitung in meiner URL-Map nur für Domänen vonGoogle Domains. Ich habe versucht, die restlichen Domänen zum selben DNS-Anbieter/Dienst zu migrieren (Google Cloud DNS), aber die Weiterleitung funktionierte trotzdem nicht. Irgendeine Art HTTP-Weiterleitung auf niedrigerer Ebene oder vielleicht eine Integration zwischen GCP und Google Domains? Ich weiß nicht, so etwas habe ich noch nie gesehen.

Wieder einmal habe ich versucht, der HTTP-zu-HTTPS-Umleitung zu folgenBeispiel. Auch hier hat es nicht funktioniert. Wenn Sie das Beispiel durchgehen, werden Sie beim Zugriff auf die HTTP-URL immer auf einen 404-Fehler stoßen.

Wenn Sie jedoch der URL-Zuordnung eine Hostregel mit einem Pfad-Matcher wie diesem hinzufügen:

defaultUrlRedirect:
  httpsRedirect: true
  redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
  stripQuery: false
hostRules:
- hosts:
  - '*'
  pathMatcher: path-matcher-wildcard
kind: compute#urlMap
name: app-http-url-map
pathMatchers:
- defaultUrlRedirect:
    httpsRedirect: true
    redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
    stripQuery: false
  name: path-matcher-wildcard
selfLink: https://www.googleapis.com/compute/v1/projects/my-project-id/global/urlMaps/app-http-url-map

Ihr gesamter Datenverkehr wird auf HTTPS umgeleitet. :)

verwandte Informationen