I have a VM that has 3 applications hosted on it. All the apps are working fine with the VM's public IP and port (e.g. 34.44.55.66:{port})
I now want to have all these behind a Cloud Load Balancer. I've done the following for it.
The load balancer is created without any issues. However, only the default path works fine. Refer to the details below (consider the LB IP as 55.66.77.88).
55.66.77.88: Website-1 opens without any issue (default path)
55.66.77.88/website-1: Website-1 shows error messages in the browser console
55.66.77.88/website-2: Website-2 shows error messages in the browser console
55.66.77.88/api-1: API-1 shows an error message in the browser console
GET http://55.66.77.88/api-1 404 (Not Found)
Whenever I map any of the above backend services with the default path, they work fine. However, they do not work as expected when the path is entered in the browser.
Any advice will be appreciated.
Keep in mind that, in your configuration, there isn't URL rewrite action. That means your request
55.66.77.88/website-1/index.html
will reach the backend on this path
# Backend bucket example
gs://my-bucket/website-1/index.html
# Instance group backend
<backend>/website-1/index.html
# Network Endpoint Group backend
<NEG>/website-1/index.html
The base path provided to the load balancer is forwarded. When you haven't additional path in the forward, it works (case of the root path 55.66.77.88/
)
You can override the behavior in the advanced mode, and you can define URL rewrite for each of your rules.
You can define rewrite rule like this in the console
Click on advanced configuration
Then click on add host and path rule
Put * in the host as you did
Then click on the pencil of the path rule section to define the rule by default. Here again, select your backend by default. no special rewrite, it's the default path.
Now click on add path rule.
Add your matching paths. And only / in the rewrite URL part (you can rewrite your host if the backend rely on the host name, but it doesn't seem your case)
Do this for all your backend and test it (let 3 - 5 minutes to propagate your update to the edge node)