تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Creating HTTP Redirect Listener0:00

Let's now configure two listeners on the application load balancer. One to redirect traffic from HTTP to HTTPS, to ensure all the traffic reaching our application is encrypted. And the other is to forward HTTPS traffic to the target group. So let's create the first listener, and we are going to call it ALPHTTPListener. And this one is of type AWS Elastic Load Balancing V2 Listener. For the properties, we are going to set the load balancer ARN, and we are going to refer to the application load balancer. For the protocol, it's HTTP, for the port, it's AT. And for the default actions, we are going to have a single action of type redirect.

Creating HTTPS Forward Listener0:43

For the protocol, it's HTTP, for the port, it's AT. And for the default actions, we are going to have a single action of type redirect. And for the redirect configuration, we are going to set the protocol to HTTPS, the port to 443, the host as it is, the path as it is, the query as it is, and the status code of the redirect is HTTP 301. So basically, this listener rule will listen to all requests coming on port 80, and it will redirect it to port 443. Now let's create the second listener, we'll call this one ALPHTTPSListener. And it's of type AWS Elastic Load Balancing V2 Listener, same as before. For the properties, we are going to set the load balancer by referring to the application.

And it's of type AWS Elastic Load Balancing V2 Listener, same as before. For the properties, we are going to set the load balancer by referring to the application load balancer. For the protocol, this time we are going to choose HTTPS, port 443, and we are going to attach a certificate. So we will set certificate ARN, and go copy the ARN from the ACM dashboard, and paste it here. That's how we tell the load balancer which certificate to use. Now for the default actions, we are going to have one action of type forward. And for the forward configurations, we are going to set the target group by its ARN,

Configuring Target Group Weights2:10

Now for the default actions, we are going to have one action of type forward. And for the forward configurations, we are going to set the target group by its ARN, and we are going to refer to the EC2 target group. And for the weight, we will set it to one. Here we can configure multiple target groups on a listener and configure the weight of each target. That way we can control the ratio of traffic to be forwarded to each group. So for example, if you are using Lambda and decide at some point that you want to move to EC2 targets, you can configure the listener to forward 1% of the traffic to the new EC2 targets and the remaining to Lambda.

Adding Stack Outputs2:49

to EC2 targets, you can configure the listener to forward 1% of the traffic to the new EC2 targets and the remaining to Lambda. You can then increase this ratio gradually until you feel confident about your EC2 servers and the load they can take. Now while we are at it, let's configure the output of this stack. So the first output is going to be EC2 instance 1 public IP address, and we are going to get the attribute from the EC2 instance 1 resource, the public IP attribute, we will use this to SSH into the instance later. And for the second output, EC2 instance 2 public IP address, and we are going to get the public IP address of instance 2.

Deploying and Health Checks3:35

And for the second output, EC2 instance 2 public IP address, and we are going to get the public IP address of instance 2. Now for the load balancer DNS output, we are going to get the DNS name of the application load balancer. We will use this in our DNS records to point requests to our domain to the load balancer. Now let's deploy our stack, I'm going to paste the command we executed earlier. And wait for the updates. Once the updates are complete, we will see that the targets appear unhealthy on the target group. And that's because the load balancer is sending the health check requests, but the instances

group. And that's because the load balancer is sending the health check requests, but the instances aren't responding. Because there is nothing on those instances that listen on port 80. That's what we will use Nginx for. In the next video, we will provision our servers to listen to requests on port 80 and proxy them to our Laravel application.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟