4
votes

I'm just starting with the AWS...

I have 1 EC2 Instance, which is running WordPress (WordPress powered by Bitnami image from the Marketplace - https://aws.amazon.com/marketplace/pp/B007IP8BKQ). Everything works fine, I can access both front and back-end of the WP installation running from standard HTTP.

The problem starts when I connect the Instance to the ELB and I'm trying to access the site via the HTTPS.

I've run through the process of setting up the SSL certificate using the ACM and applied the cert to the ELB. I've also got the 443 and 80 port enabled on the security group for the EC2 instance. The port forwarding on the ELB is set up for both 443 and 80 to go to 80 and my WP config file is set up to check the HTTP_X_FORWARDED_PROTO header to stop WP getting into an infinite redirect loop.

I think this is all working fine, as I can access the site via the HTTPS and browse the pages. However, when I attempt to log in I am redirected to HTTP and to solve this problem I have set WP site URL and WP home URL to HTTPS. This then results in numerous 503 errors (503 Service Unavailable: Back-end server is at capacity). From the AWS Dashboard, I can see the Instance is running just fine.

I've researched quite a lot to make sure I have everything set up correctly (some threads I've come across - Link 1 Link 2 ) and everything seems fine (but something is obv wrong).

Any suggestions on how to get the ELB to work?

1
@jbird I have, thank you. I'm already checking the header in my config file: if( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ){ $_SERVER['HTTPS'] = 'on'; }Ilona
This then results in numerous 503 errors -- The 503 error is sometimes returned by ELB in cases when "the backend server is at capacity" is not necessarily an accurate description of the problem. Have you checked the the web server logs and see if these failing requests are actually being seen by the web server, and what the results are of those requests?Michael - sqlbot
I'm quite new to the AWS, how do I access these, @Michael-sqlbot ?Do I need to install CloudWatch or can I just access them via ftp/ssh?Ilona
The logs on the server, you'd ssh to the server for those. The filename and location vary, but sudo ls -ltr /var/log and examine the last few entries is usually a good bet. For ELB classic, see access log collection. The logs are written into S3, where you fetch them and read them.Michael - sqlbot

1 Answers

0
votes

In your .htaccess file in your Wordpress root directory, have you tried to add in

<IfModule mod_setenvif.c>
  SetEnvIf X-Forwarded-Proto "^https$" HTTPS
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
  RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Also make sure that in your wp_options table that you have siteurl set to https:// and home is set to https://