google-cloud-platformgoogle-cloud-load-balancer

GCP Load Balancer - Host and path rules not working


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})

  1. React JS website 1 (port 3001)
  2. React JS website 2 (port 3002)
  3. Express JS API 1 (port 3003)

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).

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.


Solution

  • 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

    enter image description here

    Do this for all your backend and test it (let 3 - 5 minutes to propagate your update to the edge node)