0

I have a website in AWS hosted in an EC2 instance. I successfully configured SSL certificate via Classic Load Balancer and I can ONLY access https version of my website.

I am getting request timed out on the HTTP version of my website.

What I want to do is to permanently redirect the traffic from HTTP to my HTTPS site.

I don't want to do it via .htaccess since AWS does not recommend it.

I've been trying different configs in my /etc/apache2/site-available/000-default.conf file but still doesn't work.

Here are some configs I tried

this is the first one

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =replaced-this-with-my-domain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

and this is another one

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Redirect / https://replaced-this-with-my-domain.com/

</VirtualHost>

Do I need to edit other configurations other than the /etc/apache2/site-available/000-default.conf file?

Dave M
  • 4,514
  • 22
  • 31
  • 30
Kim Carlo
  • 101
  • 2
  • Hi Kim, I think this should be fine. Also, just a word of caution, please do enable Stickiness on your ELB so that you can prevent `TOO_MANY_REDIRECTS` error on your application. – Piyush Baderia Dec 09 '19 at 14:50
  • @PiyushBaderia, I enabled stickiness but i'm not sure if i did it correctly. I tried enabling stickiness for port 80 and 443, but now I get error 503 for both HTTP and HTTPS – Kim Carlo Dec 10 '19 at 15:08
  • Would it be possible for you to send me the config that you are using on your load balancer to enable stickiness? I enabled Load Balancer Generated Cookie Stickiness with an expiration period of 3600 seconds (1 hour) and it worked perfectly for me. – Piyush Baderia Dec 12 '19 at 14:29

0 Answers0