I'm using Elastic Beanstalk, and I installed my SSL certificate in the load balancer of an EC2 instance belonging to the EB. Every time the server is not healthy, the load balancer delete the instance and creates a new one, which means I'm gonna lose my redirection codes and SSL certificate that are set up inside the instance level.
So, I got to install my SSL certificate on the load balancer through AWS ACM. However, how can I redirect HTTP to HTTPS on the load balancer? If I still leave the redirection codes in the server, the load balancer is gonna remove the redirection codes when the instance is not healthy.
Is setting up redirection inside the instance the only way possible here?
UPDATE
I found some solution that is done under .ebextensions
. I'm currently working on Apache server. What I found is the following:
I made a file httpd_redirect.conf
under .ebextensions
with the below contents.
files:
"/etc/httpd/conf.d/httpd_redirect.conf" :
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]