Sachin Vairagi
Sachin Vairagi

Reputation: 5344

AWS Application Load Balancer - https not working properly

I have a web application developed with React JS, for server side rendering, I am using NodeJS. Following is the overall architecture -

  1. Deployed React JS app on EC2 - Ubuntu 18.04 with Nginx
  2. Obtained SSL from AWS ACM
  3. Attached ALB to EC2 instance, added 2 listeners - PORT 80, PORT 443 (Forwarding request to target group on PORT 80)
  4. Added A record on Godaddy with EC2 elastic IP, added CNAME record www pointing to ALB

Following is my nginx config file -

server {
        server_name mydomain.ai;
        return 301 https://www.mydomain.ai$request_uri;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    #server_name www.mydomain.ai;

    if ($host !~ ^www\.) {
        rewrite ^ https://$host$request_uri permanent;
    }

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location /error {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass        http://127.0.0.1:8000;
    }
    
    location /aws/ {
        try_files $uri $uri/ /aws/aws.html;
    }
}

server {
  listen *:443 default_server;
  server_name mydomain.ai www.mydomain.ai;
  
  if ($host !~ ^www\.) {
        rewrite ^ https://$host$request_uri permanent;
    }

  location / {   
    proxy_hide_header 'Access-Control-Allow-Origin';
    add_header 'Access-Control-Allow-Origin' "*" always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    proxy_pass https://localhost:8000;
    proxy_http_version 1.1;
  }

}

When I type https://mydomain.ai it throws "ERR_SSL_PROTOCOL_ERROR", however following cases are working fine -

mydomain.ai //redirected to https://www.mydomain.ai
http://mydomain.ai //redirected to https://www.mydomain.ai
http://www.mydomain.ai //redirected to https://www.mydomain.ai

Can anyone please help me?

Upvotes: 0

Views: 1331

Answers (1)

Amit Meena
Amit Meena

Reputation: 4454

I think you forgot to attach the procured certificate to ALB.

It can be done from AWS console by following the steps mentioned: https://aws.amazon.com/premiumsupport/knowledge-center/associate-acm-certificate-alb-nlb/

Upvotes: 0

Related Questions