This document is the first step in setting up an HTTP(S) load balancer. Before you start, make sure that you are familiar with overall HTTP(S) Load Balancing concepts.
Google Cloud Platform (GCP) HTTP(S) Load Balancing provides global load balancing for HTTP(S) requests destined for your instances.
Global load balancing requires that you use the Premium Tier of Network Service Tiers.
You can configure URL rules that route some URLs to one set of instances and route other URLs to other instances. Requests are always routed to the instance group that is closest to the user, provided that group has enough capacity and is appropriate for the request. If the closest group does not have enough capacity, the request is sent to the closest group that does have capacity.
HTTP(S) Load Balancing supports both IPv4 and IPv6 addresses for client traffic. Client IPv6 requests are terminated at the load balancing layer, then proxied over IPv4 to your backends.
HTTP requests can be load balanced based on port 80 or port 8080. HTTPS requests can be load balanced on port 443.
The load balancer acts as an HTTP/2 to HTTP/1.1 translation layer, which means that the web servers always see and respond to HTTP/1.1 requests, but that requests from the browser can be HTTP/1.0, HTTP/1.1, or HTTP/2. HTTP/2 server push is not supported.
Before you begin
HTTP(S) Load Balancing uses instance groups to organize instances. Make sure you are familiar with instance groups before you use load balancing.
If you want to jump right in and build a working load balancer for testing, the following guides demonstrate two different scenarios using the HTTP(S) Load Balancing service. These scenarios provide a practical context for HTTP(S) Load Balancing and demonstrate how you might set up load balancing for your specific needs.
The rest of this page discusses more details about how load balancers are constructed and how they work.
Creating a cross-region load balancer
You can use a global IP address that can intelligently route users based on proximity. For example, if you set up instances in North America, Europe, and Asia, users around the world will be automatically sent to the backends closest to them, assuming those instances have enough capacity. If the closest instances do not have enough capacity, cross-region load balancing automatically forwards users to the next closest region.
Creating a content-based load balancer
Content-based or content-aware load balancing uses HTTP(S) Load Balancing to
distribute traffic to different instances based on the incoming HTTP(S) URL. For
example, you can set up some instances to handle your video
content and another set to handle everything else. You can configure your load
balancer to direct traffic for
example.com/video to the video servers
example.com/ to the default servers.
Content-based and cross-region load-balancing can work together by using multiple backend services and multiple regions. You can build on top of the scenarios above to configure your own load balancing configuration that meets your needs.
Your HTTP(S) Load Balancing service can be configured and updated through the following interfaces:
gcloudcommand-line tool: a command-line tool included in the Cloud SDK. The HTTP(S) Load Balancing documentation calls on this tool frequently to accomplish tasks. For a complete overview of the tool, see the gcloud Tool Guide. You can find commands related to load balancing in the
gcloud computecommand group.
You can also get detailed help for any
gcloudcommand by using the
gcloud compute http-health-checks create --help
The Google Cloud Platform Console: Load balancing tasks can be accomplished through the Google Cloud Platform Console.
The REST API: All load balancing tasks can be accomplished using the Google Cloud Load Balancing API. The API reference docs describe the resources and methods available to you.
Notes and Restrictions
- HTTP(S) Load Balancing supports the
HTTP/1.1 100 Continueresponse.
- If your load balanced instances are running a public operating system image supplied by Google Cloud Platform, then firewall rules in the operating system will be configured automatically to allow load balanced traffic. If you are using a custom image, you have to configure the operating system firewall manually. This is separate from the GCP firewall rule that must be created as part of configuring an HTTP(S) load balancer.
- Load balancing does not keep instances in sync. You must set up your own mechanisms, such as using Deployment Manager, for ensuring that your instances have consistent configurations and data.
- The HTTP(S) load balancer does not support sending an HTTP DELETE with a body
to the load balancer. Such requests will receive an error message:
Error 400 (Bad Request)!! Your client has issued a malformed or illegal request.Only DELETE requests without bodies are supported.
Load balanced traffic does not have the source address of the original client
Traffic from the load balancer to your instances has an IP address in the
18.104.22.168/16. When viewing logs on your
load balanced instances, you will not see the source address of the
original client. Instead, you will see source addresses from this range.
Getting a permission error when trying to view an object in my Cloud Storage bucket
In order to serve objects through load balancing, the Cloud Storage objects must be publicly accessible. Make sure to update the permissions of the objects being served so they are publicly readable.
URL doesn’t serve expected Cloud Storage object
The Cloud Storage object to serve is determined based on your URL map and the URL that you request. If the request path maps to a backend bucket in your URL map, the Cloud Storage object is determined by appending the full request path onto the Cloud Storage bucket that the URL map specifies.
For example, if you map
gs://[EXAMPLE_BUCKET], the request to
https://<GCLB IP or Host>/static/path/to/content.jpg will try to serve
gs://[EXAMPLE_BUCKET]/static/path/to/content.jpg. If that object doesn’t
exist, you will get the following error message instead of the object:
The specified key does not exist.
Compression isn't working
If responses served by HTTP(S) Load Balancing are not compressed but should be,
check to be sure that the web server software running on your instances is
configured to compress responses. By default, some web server software
automatically disables compression for requests that include a
which indicates that the request was forwarded by a proxy. Because it is a
proxy, HTTP(S) Load Balancing adds a
Via header to each request as
required by the HTTP specification.
To enable compression, you may have to override your web server's default
configuration to tell it to compress responses even if the request had a
If you are using the nginx web server
software, modify the
nginx.conf configuration file to enable
compression. The location of this file depends on where nginx is installed. In
many Linux distributions, the file is stored at
allow nginx compression to work with HTTP(S) Load Balancing, add the following
two lines to the
http section of nginx.conf:
gzip_proxied any; gzip_vary on;
The first line enables compression even for requests forwarded
by a proxy like HTTP(S) Load Balancing. The second line adds a
Vary: Accept-Encoding header to responses.
Vary: Accept-Encoding notifies
caching proxies such as Cloud CDN that they should maintain separate cache
entries for compressed and non-compressed variants of compressible resources.
After modifying nginx.conf, you need to restart nginx before it will use the new
configuration. In many Linux distributions, nginx can be restarted by running
sudo service nginx restart or
- Create a cross-region HTTP(S) load balancer
- Create a content-based HTTP(S) load balancer
- Add a backend bucket to a content-based load balancer
- Read conceptual information about HTTP(S) Load Balancing
- Read about global forwarding rules
- Read about setting up URL maps or read conceptual information about URL maps
- Configure SSL certificates
- Create SSL policies