I want to help you to fix your current limitation.
A URL redirect redirects your domain's visitors from one URL to another.
Before deploying a URL map, make sure you validate the URL map configuration to ensure that the map is routing requests to the appropriate backends as intended. You can do this by adding tests to the URL map configuration.
Use the gcloud compute url-maps validate
command to validate URL map configuration.
gcloud compute url-maps validate --source PATH_TO_URL_MAP_CONFIG_FILE
PATH_TO_URL_MAP_CONFIG_FILE: Replace with a path to the file that contains the URL map configuration for validation.
Validating changes to an existing load balancer's URL map
If you have an existing load balancer that needs changes to the URL map, you can test those configuration changes before making them live.
- Export the load balancer's existing URL map to a YAML file.
gcloud compute url-maps export URL_MAP_NAME \
--destination PATH_TO_URL_MAP_CONFIG_FILE \
--global
- Edit the YAML file with new configuration. For example, if you want to edit an external HTTP(S) load balancer and send all requests with the path
/video
to a new backend service called video-backend-service
, you can add tests to the URL map configuration as follows:
Existing URL map configuration with a single default web-backend-service
:
kind: compute#urlMap
name: URL_MAP_NAME
defaultService: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service
Edited URL map configuration with added path matcher and tests for both the default web-backend-service
and the new video-backend-service
backend service:
kind: compute#urlMap
name: URL_MAP_NAME
defaultService: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service
hostRules:
- hosts:
- '*'
pathMatcher: pathmap
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service
name: pathmap
pathRules:
- paths:
- /video
- /video/*
service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/video-backend-service
tests:
- description: Test routing to existing web service
host: foobar
path: /
service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service
- description: Test routing to new video service
host: foobar
path: /video
service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/video-backend-service
- Validate the new configuration.
gcloud compute url-maps validate --source PATH_TO_URL_MAP_CONFIG_FILE
If all tests pass successfully, you should see a success message such as:
Successfully validated [https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/urlMaps/URL_MAP_CONFIG_FILE_NAME
If the tests fail, an error message appears. Make the required fixes to the URL map config file and try validating again.
Error: Invalid value for field 'urlMap.tests': ''.
Test failure: Expect URL 'HOST/PATH' to map to service 'EXPECTED_BACKEND_SERVICE', but actually mapped to 'ACTUAL_BACKEND_SERVICE'.
- Once you know that the new configuration works and does not impact your existing setup, you can import it into the URL map. Note that this step will also deploy the url map with the new configuration.
gcloud compute url-maps import URL_MAP_NAME \
--source PATH_TO_URL_MAP_CONFIG_FILE \
--global
Important: If you originally set up your load balancer in the Cloud Console, the URL map name is the same as your load balancer's name.
Have fun!