重定向基于" Accept-Language"请求标头会导致Google Cloud CDN出错

时间:2018-06-11 10:10:46

标签: google-cloud-platform google-compute-engine google-cloud-cdn

我目前正在" Google Compute Engine"上设置Nginx服务器谷歌的Load Balancer / CDN组合背后:

Website visitor <---> CDN <---> Load Balancer <---> Nginx on Google Compute Engine

我想将访问者从https://www.example.org/重定向到https://www.example.org/de/https://www.example.org/en/,具体取决于&#34; Accept-Language&#34;客户端请求中的HTTP-Header。为此,我在nginx.conf配置文件中使用以下代码:

set $language_suffix "en";
if ($http_accept_language ~* "^de") {
  set $language_suffix "de";
}

location = / {
  add_header Vary "Accept-Language";
  return 303 https://www.example.org/$language_suffix/;
}

但是,上面的配置会导致502错误:

~> curl -I https://www.example.org/
HTTP/2 502 
content-type: text/html; charset=UTF-8
referrer-policy: no-referrer
content-length: 332
date: Mon, 11 Jun 2018 09:57:55 GMT
alt-svc: clear

我该如何解决这个问题?

更新

XXX.XXX.XXX.XXX - "HEAD https://www.XXXXXXX.com/" 502 106 "curl/7.60.0" {
 httpRequest: {
  cacheLookup:  true   
  remoteIp:  "XXX.XXX.XXX.XXX"   
  requestMethod:  "HEAD"   
  requestSize:  "38"   
  requestUrl:  "https://www.XXXXXXX.com/"   
  responseSize:  "106"   
  status:  502   
  userAgent:  "curl/7.60.0"   
 }
 insertId:  "XXXXXXXXXXXXX"  
 jsonPayload: {
  @type:  "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"   
  statusDetails:  "failed_to_pick_backend"   
 }
 logName:  "projects/crack-triode-XXXXXXXX/logs/requests"  
 receiveTimestamp:  "2018-06-11T03:33:10.864056419Z"  
 resource: {
  labels: {
   backend_service_name:  ""    
   forwarding_rule_name:  "XXX-werbserver-ipv4-https"    
   project_id:  "crack-triode-XXXXXXXX"    
   target_proxy_name:  "XXX-werbserver-loadbalancer-target-proxy-2"    
   url_map_name:  "XXX-werbserver-loadbalancer"    
   zone:  "global"    
  }
  type:  "http_load_balancer"   
 }
 severity:  "WARNING"  
 spanId:  "XXXXXXXXXXXXXX"  
 timestamp:  "2018-06-11T03:33:10.088466141Z"  
 trace:  "projects/crack-triode-XXXXXXXX/traces/XXXXXXXXXXXXXXX"  
}

1 个答案:

答案 0 :(得分:0)

您必须将请求uri从/更改为其他返回HTTP-Status 200的请求。我现在正在使用/robots.txt。可以在以下位置更改设置:

https://console.cloud.google.com/compute/healthChecks

enter image description here