The set up:
- Angular website aaa.com served in bucket as static website.
- VM with external IP 1.1.1.1 with running backend with one endpoint /test (nginx,
gunicorn, django restframework, everything is up and running). - Load balancer with external IP 2.2.2.2.
Load balancer configured paths:
host: aaa.com, path: /* -> bucket website;
host: aaa.com, path: /test -> VM backend;
everything was configured on google website according to tutorials
“A” record linked to 1.1.1.1 in DNS settings (domain name registered on Namecheap)
If try http://aaa.com in browser -> works perfectly.
If try direct request to http://2.2.2.2/test -> works perfectly. (bypass load balancer)
But if try http://aaa.com/test in browser returns error: 404 not found.
Seems like load balancer works but won`t communicate with backend VM. What could be the reason?
Igor58exp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Because you have a rule path: /* -> bucket website;
that redirects all requests to the bucket website, so requests don’t go to the VM at all.
Also you assumption that 404 is caused by the load balancer being unable to communicate with the backend VM is incorrect. All errors in 4xx range indicate that the error is in the client request and backend is fine. 404 means that you send a request for an object that doesn’t exist on the server.
If there is a problem on the backend you will get an error in 5xx range. Most typical error code for load balancer problem is 5xx.
A few things to check:
- Make sure to configure HealthCheck for the load balancer backend.
- Log in to VM and check the logs to see if health check requests are coming through.
- Check the load balancer target group (NEG or MIG) to see if it shows that the backend is healthy.
Also, GCP load balancers takes some time to settle after you configure them for the first time. When you first create it, you’ll see a bunch of empty response / connection reset errors. Those typically go away after 2-3 minutes.
3