Usama
Usama

Reputation: 61

HTTP to HTTPS redirection not working on AWS ALB

I am using ECS for WordPress site and using Application Load Balancer (ALB) for load balancing and offloading SSL. ALB is using 2 different listeners on both port 80 and 443. The redirection rule is attached to the port 80 listener which is:

Redirect tohttps://#{host}:443/#{path}?#{query} 
Status code:HTTP_301

The webserver is nginx with php-fpm and listening on port 80. There is no redirection being done at nginx.

So, basically what I want is http (user req) -> https (ALB redirection) -> http (nginx)

Now the problem is that the ALB is not redirecting the http traffic for the main home page like

http://example.com -> http://example.com (ALB no redirection) -> http://example.com (nginx)

but it works with the same domain but different URL like:

http://example.com/page -> https://example.com/page (ALB redirection) -> http://example.com/page (nginx)

Edit: Here is the link to the ALB listener rules.

Upvotes: 6

Views: 7253

Answers (3)

Valentino
Valentino

Reputation: 542

I had the same problem. Removed the HTTP listener, added it back again, and it began to work properly.

Upvotes: 1

David Rinck
David Rinck

Reputation: 6966

If the other answer doesn't work, double-check that your Security group allows inbound connections on port 80

  1. Go to your load balancer
  2. Click on Description. Scroll down to Security Groups to find your security group
  3. Click on your Security group and check that inbound connections are allowed on port 80. If not add them. Even though you are redirecting traffic from port 80, they'll never make it to that step if they are blocked here.

security group rules

Upvotes: 10

chris
chris

Reputation: 37440

Not sure what you're doing wrong, but the port 80 listener can handle the redirect to https.

You can update the port 80 listener manually, or if you're using cloudformation it would look like:

Listener80:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    DefaultActions:
      - RedirectConfig:
          Port: 443
          Protocol: HTTPS
          StatusCode: HTTP_301
        Type: redirect
    LoadBalancerArn: !Ref ALB
    Port: 80
    Protocol: HTTP

The listener configuration looks like:

Recirect Listener - Console

Upvotes: 0

Related Questions