- Newest
- Most votes
- Most comments
The auto Agent answer seems to be on the right track, but a few more specific points
- What is your target group configuration? Your frontend connections are listening on HTTP 80, and then redirecting to HTTPS 443; but the connection from the ELB to the target is a completely separate connection. I'm guessing the target group is configured to connect to the backend Nginx instances on HTTP 80, which is why its timing out (504 means server didn't reply), since your security group on the instance is only allowing 443 inbound
502 usually happens when you try and do something like:
- Server is listening on port 443 for HTTPS
- but you connect on port 443 with HTTP
Reach ability analyzer is really helpful in debugging these sorts of issues: https://docs.aws.amazon.com/vpc/latest/reachability/what-is-reachability-analyzer.html
Based on the information provided, there are a few potential causes for the 504 Gateway Timeout and 502 Bad Gateway errors you're experiencing with your Application Load Balancer (ALB) and EC2 instance running WordPress with Nginx. Let's address these issues:
- 504 Gateway Timeout Error: This error typically occurs when the ALB fails to receive a response from the target (your EC2 instance) within the configured timeout period. Possible causes include:
- The Nginx server on your EC2 instance is not responding quickly enough.
- There might be connectivity issues between the ALB and your EC2 instance.
- The EC2 instance might be overloaded or not have enough resources to handle the requests.
To troubleshoot this:
- Check if your EC2 instance's security group is correctly configured to allow incoming traffic from the ALB on port 443.
- Verify that Nginx is properly configured to listen on port 443 and that the SSL certificate is correctly set up.
- Monitor your EC2 instance's resource utilization to ensure it's not overloaded.
- Consider increasing the ALB's timeout settings if your WordPress site requires more time to process requests.
- 502 Bad Gateway Error: This error usually indicates that the ALB received an invalid response from the target. Possible causes include:
- Nginx is not properly configured to handle the requests.
- There might be an SSL/TLS negotiation issue between the ALB and Nginx.
To address this:
- Ensure that Nginx is correctly configured to handle HTTPS traffic.
- Verify that the SSL certificate used by Nginx is valid and properly installed.
- Check Nginx error logs for any specific issues related to the requests it's receiving.
Additional considerations:
- Make sure the ALB's target group is configured to use HTTPS (port 443) to communicate with your EC2 instance.
- Verify that the health check settings in your target group are appropriate for your WordPress site.
- Check if your RDS and S3 connections are working correctly, as issues with these could also lead to timeouts or errors.
To further debug:
- Enable access logs for your ALB to get more detailed information about the requests and responses.
- Review the Nginx access and error logs on your EC2 instance for any specific error messages or patterns.
- Use tools like curl or a web browser's developer tools to test the connection directly to your EC2 instance to isolate whether the issue is with Nginx or the ALB.
By systematically checking these areas, you should be able to identify and resolve the root cause of the 504 and 502 errors you're experiencing.
Sources
Resolve HTTP connection errors with Application Load Balancer | AWS re:Post
Troubleshoot your Application Load Balancers - Elastic Load Balancing
Troubleshoot a Classic Load Balancer: HTTP errors - Elastic Load Balancing
Relevant content
asked 4 years ago
asked 4 years ago
asked 2 years ago

https://snipboard.io/N0X1gV.jpg (Nginx) https://snipboard.io/BKmdSA.jpg (Load Balancer) https://snipboard.io/Ve9Lvr.jpg (LB-SG) https://snipboard.io/mDOQhG.jpg (EC2-SG)
You showed the Listener config, but not the Target Group config. The Target Group settings determine which port/protocol are used for backend connections. Also, is the SG referenced in the EC2-SG the ELB SG?
You may want to open a technical support case so someone can look at your exact resources
https://snipboard.io/HCEneY.jpg (Port80) https://snipboard.io/fYJcvL.jpg (Port443)
Those screenshots show 0 instances registered to the HTTP target group (do you need it at all if its unused?) and 1 instance on the HTTPS one. The instance is draining, which I'm guessing means it was on an ASG, went unhealthy, and is being replaced. So you'll want to see why the instance can't take traffic from the ELB. You'll either want to work with someone who can architect this environment for you, or if you just need troubleshooting help, open a technical support case so someone can look at your AWS configurations in details