0

I've setup a Load Balancer in AWS which routes traffic to an Apache Ubuntu server.

When I browse to my URL, sometimes everything goes well. Then I hit the Refresh button and I start getting 502 errors when downloading some files. It's different files each time.

Then I hit Refresh again and everything goes fine.

I'm currently the only one using the server.

My Load balancer is setup like this:

  • Availability Zones: us-east-1a and us-east-1b
  • Security groups: port 80 and 443 opened
  • Listeners: Port 80 redirect to port 443, port 443 forwards to my Target

My target group is configured like this:

  • Target type: instance
  • Protocol: HTTP: 80
  • Load balancer: My load balancer name
  • Register targets: I have 1 instance running in each zone.

My Auto Scaling Group is configured like this:

  • Desired capasity: 2
  • Minimum capacity: 2
  • Maximum capacity: 5
  • Availability zones: us-east-1a, us-east-1b

My apache server is configured with the default install values, plus:

  • KeepAlive On
  • Timeout 120
  • KeepAliveTimeout 120
  • MaxKeepAliveRequests 100
  • AcceptFilter http none
  • AcceptFilter https none

I'm not a server guy, I'm a programmer so I really don't know what to check. I thought configuring a Load Balancer was straight forward...

Thanks for your help

EDIT 2020-08-27 15h39

I enabled the logs on the VPC and on the Load Balancer and I refreshed my page. I had an 502 error on a specific file.

In the Load Balancer logs, I see the 502 entry for the specific file. Here`s the entry - JSON formatted - in which I replaced any sentive data

[
  {
    "type": "h2",
    "time": "2020-08-27T19:20:52.547402Z",
    "elb": "app/web-server-load-balancer/**my-load-balancer-id**",
    "client:port": "*my-ip-address*:60831",
    "target:port": "10.0.0.106:80",
    "request_processing_time": 0,
    "target_processing_time": 0.013,
    "response_processing_time": -1,
    "elb_status_code": 502,
    "target_status_code": "-",
    "received_bytes": 45,
    "sent_bytes": 610,
    "request": "GET https://**my-url** HTTP/2.0",
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36",
    "ssl_cipher": "ECDHE-RSA-AES128-GCM-SHA256",
    "ssl_protocol": "TLSv1.2",
    "target_group_arn": "**my-target-group-arn**",
    "trace_id": "Root=1-5f480794-150df3bcad7fd0ac6bdfc41c",
    "domain_name": "**my-domain-name**",
    "chosen_cert_arn": "session-reused",
    "matched_rule_priority": 0,
    "request_creation_time": "2020-08-27T19:20:52.534000Z",
    "actions_executed": "forward",
    "redirect_url": "-",
    "error_reason": "-",
    "target:port_list": "10.0.0.106:80",
    "target_status_code_list": "-",
    "classification": "-",
    "classification_reason": "-"
  }
]

I don`t know if those data can help you helping me!

EDIT 2020-08-31 (1)

I opened the two VMs in the Firewall to access them directly. When I access each server directly, I do not get the 502 errors at all. When I access via the Load balancer, I get the 502.

EDIT 2020-08-31 (2)

I changed my load balancer to route the HTTP traffic to the instance instead of redirect it to the 443 port.

On port 80, I do not get 502 errors. I hard-refreshed many many times and did not get 502. As soon as access the load balancer with https, I start to get 502 errors. I remember you that when I directly access the VM with https, I do not get 502.

  • When I have a 502 on a file, the request does not reach Apache. I do not see the request neither in the access.log and error.log file – vIceBerg Aug 26 '20 at 22:34
  • OK, if the 502 came from the load balancer, then you get to make wild guesses. – Michael Hampton Aug 26 '20 at 22:58
  • You could enable VPC flow logs to see what's happening on the network. They capture network flow metadata, not packet contents, but they could give you some clues. docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html – Tim Aug 27 '20 at 9:17
  • I'll create a new VPC, setup a new load balancer and enable the logs on my VPC. I'll keep you in touch. – vIceBerg Aug 27 '20 at 15:58
  • The log entry doesn't specify the reason for the 502 error. But it does say that it received 45 bytes. That's probably not enough for full response headers. This suggests your app may be crashing in the process of sending a response. – Michael Hampton Aug 27 '20 at 20:44
1

I came across this forum post: AWS Developer Forum

The last entry actually gave me the answer:

Ensure you're not using Apache's event MPM module (default) when behind a ALB/ELB. It dynamically closes connections. Try worker MPM.

I changed my Apache config to use worker MPM and as far as it goes, I did not had any 502 errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.