การเปลี่ยนเส้นทาง HTTPS ของ Cloud Load Balancing ไม่ทำงานสำหรับบางโฮสต์
ในตัวจัดสรรภาระงานของฉันฉันมีโฮสต์ 6 โฮสต์ในทุกโฮสต์ แต่การเปลี่ยนเส้นทาง HTTPS หนึ่งรายการทำงานได้อย่างสมบูรณ์ ฉันพยายามกำหนดค่าทุกอย่างที่เป็นไปได้และอ่านเอกสารทั้งหมดที่ Google มีให้ (แนวคิดคำแนะนำวิธีใช้ข้อมูลอ้างอิง) เช่นhttps://cloud.google.com/load-balancing/docs/https/setting-up-http-https-redirect#setting_up_the_http_load_balancer ไม่มีประโยชน์ ...
สิ่งที่ทำให้ฉันแทบคลั่งก็คือในเดียวกันurl-map
ก็มีโฮสต์ซึ่งการเปลี่ยนเส้นทาง HTTPS ทำงานได้ 100% ซึ่งเป็นสำเนา "เหมือนกัน" ของอันที่ใช้ไม่ได้ นี่คือของฉันurl-map
กับโฮสต์สองคนที่แยกกัน:
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/hello
ผลตอบแทน:
{
"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/hello
ผลตอบแทน
{
"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"
}
ฉันคิดว่ามันอาจจะแตกต่างกันบ้างในการกำหนดค่าบริการแบ็กเอนด์ / ที่เก็บข้อมูล แต่ก็เหมือนกัน
เอาต์พุตเพิ่มเติม:
# 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
คำตอบ
จากข้อมูลที่คุณกรุณาให้มาและในสถานการณ์ที่คล้ายคลึงกันอาจเป็นไปได้ว่าคุณได้กำหนดค่าแมป URL หนึ่งรายการสำหรับการเปลี่ยนเส้นทาง HTTP เป็น HTTPS ในขณะที่คุณต้องสร้างการแม็พ HTTP URL ที่มีจุดประสงค์เดียวคือเปลี่ยนเส้นทางการรับส่งข้อมูลไปยังแผนที่ HTTPS URL ที่คุณกำหนดค่า hostRules และ pathMatchers
ในตัวอย่างนี้"web-map-http" ถูกสร้างขึ้นเพื่อเปลี่ยนเส้นทางการรับส่งข้อมูล HTTP ไปยังแผนที่ HTTPS URL เท่านั้น "web-map-https" และ "web-map-https" คือที่ที่คุณกำหนดค่า hostRules และ pathMatchers
Cloud Console ควรแสดงตัวจัดสรรภาระงานสองตัว
การสร้างแผนที่ URL หนึ่งรายการสำหรับการเปลี่ยนเส้นทาง HTTP ไปยัง HTTPS และกฎของโฮสต์อาจได้ผล แต่ไม่ใช่วิธีที่แนะนำ
ฉันพบว่าปัญหาไม่ได้เกิดจากตัวโฮสต์เอง แต่การเปลี่ยนเส้นทาง HTTPS ในแผนที่ URL ของฉันใช้งานได้กับโดเมนจากGoogle Domainsเท่านั้น ฉันพยายามย้ายโดเมนที่เหลือไปยังผู้ให้บริการ / บริการ DNS เดียวกัน ( Google Cloud DNS ) แต่การเปลี่ยนเส้นทางยังไม่ทำงาน การเปลี่ยนเส้นทาง HTTP ระดับล่างบางประเภทหรืออาจเป็นการผสานระหว่าง GCP และ Google Domains? ไม่รู้ไม่เคยเห็นอะไรแบบนั้น
อีกครั้งหนึ่งที่ผมพยายามที่จะทำตาม HTTP เพื่อ HTTPS เปลี่ยนเส้นทางตัวอย่างเช่น อีกครั้งไม่ได้ผลหากคุณทำตามตัวอย่างคุณจะพบข้อผิดพลาด 404 เสมอในขณะที่เข้าถึง HTTP URL
แต่ถ้าคุณเพิ่มกฎโฮสต์ที่มีตัวจับคู่เส้นทางเช่นนี้ในแมป URL:
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
การเข้าชมทั้งหมดของคุณจะถูกเปลี่ยนเส้นทางไปที่ HTTPS :)