0

I am currently setting up an Nginx server on a "Google Compute Engine" behind Google's Load Balancer/CDN combo:

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

I would like to redirect the visitor from https://www.example.org/ to either https://www.example.org/de/ or https://www.example.org/en/ depending on the value of the "Accept-Language" HTTP-Header in the client's request. For this purpose, I am using the following code in the nginx.conf configuration file:

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/;
}

But, above config leads to a 502 error:

~> 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

How can I fix this?

UPDATE:

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"  
}
duxsco
  • 331
  • 2
  • 17
  • That error response doesn't look like an error generated by or proxied by a Google HTTP(S) LB. Are you sure www.example.org resolves to your LB? If so, what does the statusDetails field in the logs say? You can find the statusDetail field by visiting https://console.cloud.google.com/logs/viewer?resource=http_load_balancer, expanding the log entry of interest, and expanding the jsonPayload field. – elving Jun 11 '18 at 19:19
  • @elving Without above Nginx config lines, the CDN/LoadBalancer resolves correctly to my Nginx webserver, meaning the content of `/index.html` is shown. After pasting above code in `nginx.conf` and doing `/etc/init.d/nginx restart`, I get the 502 status code. The same Nginx configuration has been used without a problem on a non-Google system. Btw, the redirect destination in the folder `/de/index.html` and `/en/index.html` exist. – duxsco Jun 11 '18 at 21:48

1 Answers1

0

You have to change the request uri from / to some else, that returns HTTP-Status 200. I am now using /robots.txt. The setting can be changed at:

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

enter image description here

duxsco
  • 331
  • 2
  • 17