Google HTTP load balancing enforce HTTPS

2.1k views Asked by At

I have a HTTP and HTTPS load balancer on Goole Cloud. Is it possible to set it up to enforce (redirect) all connections to HTTPS?

2

There are 2 answers

4
Matt S. On BEST ANSWER

Not at the load balancer as of June 2015.

As an alternative, you can configure your web servers to return 301 for all HTTP requests redirecting to the HTTPS version.

For Apache (from https://wiki.apache.org/httpd/RedirectSSL):

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.example.com
   Redirect permanent / https://www.example.com/
</VirtualHost>

<VirtualHost _default_:443>
   ServerName www.example.com
   DocumentRoot /my/document/root
   SSLEngine On
   # .. etc .
</VirtualHost>

For nginx (from https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom):

server {
    listen [::]:80;
    return 301 https://$host$request_uri; 
}
1
Raullen Chai On

Why bother to redirect? You could easily create new (SSL) global forwarding rule and point it to your backend service.

For example, http://107.178.251.37/ points to my HTTP backend and I've added another global forwarding rule to make it SSL: https://107.178.240.233/.