0

I am trying to redirect http connections to https connections on our server.

Here's my setup for now:

I have 2 Global Forwarding rules as follows:

Rule 1 redirects all https connections to my instance as https://app.example.com

Rule 2 redirects all http connections to my instance as http://app.example.com

I am running a Finatra server and I want to redirect http://app.example.com and app.example.com to https://app.example.com

I already setup SSL, etc. https works good but I need to manually write it everytime. Somehow I can't find out where in Google Cloud Console I can do this.

Seraf
  • 850
  • 1
  • 17
  • 34
  • 1
    Don't you want to add a rule for port 80 on GCP load balancer to redirect your traffic to port 443? – Alban Dericbourg Jul 19 '17 at 13:51
  • @AlbanDericbourg That's when you send people to the Load Balancer but I didn't want to do that, my domain name is directed to the instance IP directly. I handled this problem in the server, it was pretty straight forward. – Seraf Jul 19 '17 at 14:19

1 Answers1

0

To redirect HTTP traffic to HTTPS, you must do the following:

  1. (Prerequisite) You must have an external HTTPS load balancer (called here LB1) that is already serving HTTPS traffic on port 443.

= = = = = = = = = >As you mentioned in your issue description you have the prerequisite achieved. < = = = = = = = = =

  1. Create a partial external HTTP load balancer (called here LB2). The LB2 setup has the following:

-No backend

-The same frontend IP address used by LB1

-A redirect configured in the URL map

1. Prerequisite: Set up an external HTTPS load balancer (LB1)

If you don't already have an external HTTPS load balancer configured, use one of the following guides to complete that setup. Select a procedure for your backend type:

Compute Engine backend Backend bucket Cloud Run, App Engine, or Cloud Functions backend External backend If you already have a functioning HTTPS load balancer, skip to Redirecting traffic to your HTTPS load balancer.

2. Redirecting traffic to your HTTPS load balancer

After you have verified that your external HTTPS load balancer (LB1) is working, you can create the partial external HTTP load balancer (LB2) with its frontend configured to redirect traffic to LB1.

This example uses the 301 response code. You can instead use a different response code.

To configure the redirect with gcloud, you must import a YAML file and make sure that your target HTTP proxy points to the URL map that redirects traffic. If you're using the Cloud Console, this is handled for you.

Start the configuration

2.1 In the Google Cloud Console, go to the Load balancing page.

2.2 Under HTTP(S) load balancing, click Start configuration.

2.3 Select From Internet to my VMs, and then click Continue.

2.4 For the Name of the load balancer, enter something like http-redirect.

2.5 Keep the window open to continue.

Skip the backend configuration

2.6 Skip the Backend Configuration section. This load balancer doesn't need a backend.

Configure the redirect in the URL map

2.7 In the left column of the page, click Host and path rules.

2.8 Select Advanced host and path rule (URL redirect, URL rewrite).

2.9 Under Action, select Redirect the client to different host/path.

2.10 Leave the Prefix redirect field blank.

2.11 Under Path redirect, select Prefix redirect.

2.12 Leave the Path value field blank.

2.13 Under Redirect response code, select 301 - Moved Permanently.

2.14 Under HTTPS redirect, select Enable.

2.15 Click Done.

2.16 Keep the load balancer configuration page open to continue.

Configure the HTTP forwarding rule with the same IP address used in LB1

2.17 On the load balancer configuration page, click Frontend configuration.

2.18 Set Protocol to HTTP.

2.19 Set IP address to the same IP address that you use for your HTTPS load balancer.

2.20 Ensure that Port is set to 80 to allow HTTP traffic.

2.21 Click Done.

2.22 Keep the window open to continue.

Review the configuration

2.23 In the left panel, click Review and finalize.

2.24 Compare your settings to what you intended to create.

2.25 If everything looks correct, click Create.

When you are finished, the Cloud Console displays two load balancers

Alejandro F.
  • 410
  • 3
  • 10