Gaoridang
Gaoridang

Reputation: 79

AWS EC2 load balancing target group 'https 443' unhealthy

I am trying to secure my EC2 server with HTTPS. I have a backend application written in Node.js. Here's the basic structure of my server setup:

app.use(cors());
app.use(express.json());

app.get("/", (req, res) => {
  res.status(200).send("server running");
});

const port = process.env.PORT || 8080; // Assuming port is defined here for clarity
app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});

So far, I have completed the following steps:

  1. Created an EC2 instance.
  2. Generated an AWS domain and issued an SSL certificate.
  3. Created a Route53 hosting zone and registered records.
  4. Added 443, 80, and 8080 (for the Node.js app) ports to the EC2 security group.
  5. Created an EC2 target group.
  6. Set up a load balancer with the following rules:

(I can't upload images for low reputation...)

Despite these configurations, I am facing a couple of issues:

The health status for port 8080 is healthy, but for port 443, it is marked as unhealthy. Currently, I can only access my application through the EC2's public IPv4 address on port 8080. Any attempt to access it via HTTPS or even HTTP without specifying the port results in a timeout.

Given this situation, I am unsure how to correctly set up HTTPS for my server to ensure it is secure. Specifically, I am looking for guidance on how to integrate the issued SSL certificate with my Node.js application, ensure all traffic goes through HTTPS, and resolve the unhealthy status of port 443 as well as the timeout issues.

Could someone provide a detailed explanation or step-by-step guide on how to secure my Node.js application with HTTPS on an EC2 server, especially focusing on how to use the SSL certificate with my application, any necessary configurations on the AWS side, and troubleshooting the mentioned issues?

Upvotes: 0

Views: 807

Answers (1)

Kavindu Vindika
Kavindu Vindika

Reputation: 2737

Can you please verify whether you've configured the following;

  1. Adding Default SSL/TLS server certificate for the 443 listener in the ALB.
  2. Configure your target group to use http at port 8080 which corresponds to load balancer to send traffic. enter image description here
  3. You might need to add another listener for port 80 having permanent redirection to https. This will enforce your users to use https instead of http. enter image description here

Please Let me know if still you're getting issues even after configuring above settings.

Upvotes: 0

Related Questions