2
votes

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.

  • Created three backend services (one for each application)
  • Created Host and Path rules as below enter image description here

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 enter image description here

  • 55.66.77.88/website-2: Website-2 shows error messages in the browser console enter image description here

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

1
I suggest posting this to ServerFault, as it's not programming-related. That said: Please be sure to include formatted-text versions of your error messages as well, when you repost. This meta post lists many reasons why this is important.David Makogon

1 Answers

4
votes

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

  • Set up your default configuration (any domain, any path) enter image description here

  • 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. enter image description here

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

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)