0

我目前正在 Google 的负载均衡器/CDN 组合后面的“Google Compute Engine”上设置 Nginx 服务器:

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

我想将访问者从https://www.example.org/重定向到https://www.example.org/de/https://www.example.org/en/,具体取决于客户端请求中的“Accept-Language”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"  
}
4

1 回答 1

0

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

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

在此处输入图像描述

于 2018-06-12T22:33:15.373 回答