0

I am using an AWS Elastic Load Balancer, and have set up the following rule to convert http traffic to https.

/etc/httpd/conf.d/httpd_redirect.conf

 <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] </VirtualHost> 

However, when I access my website via its domain (www.thewhozoo.com), I can see the protocol is http and not https.

Any ideas why the rewrite rule is not working?

Thanks

More info

/etc/httpd/conf/httpd.conf

... Include conf.d/*.conf Include conf.d/elasticbeanstalk/*.conf ... 

The above is created on deployment by:

.ebextensions/myapp.config

container_commands: 01_setup_apache: command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf" files: "/etc/httpd/conf.d/httpd_redirect.conf" : mode: "000644" owner: root group: root content: | <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] </VirtualHost> 

ELB Listeners

enter image description here

1 Answer 1

2

You have a configuration snippet /etc/httpd/conf.d/ssl_rewrite.conf

Typically such snippets get loaded by an Include or IncludeOptional directive

Include conf.d/*.conf 

or

IncludeOptional conf.d/*.conf 

from your main httpd.conf.

The problem is that those snippets only apply to your main configuration and don't apply to any VirtualHost sections...

Either include those settings in the virtual host definition, or load that snippet there:

<VirtualHost *:80> ServerName www.thewhozoo.com Include /etc/httpd/conf.d/ssl_rewrite.conf </VirtualHost> 

Or even better, don't use mod_rewrite and set:

<VirtualHost *:80> ServerName www.thewhozoo.com Redirect "/" "https://www.thewhozoo.com/" </VirtualHost> 
8
  • Thanks for the great answer. If I use Redirect "/" "https://www.thewhozoo.com/", where do I put it? i.e. in which config file? Commented Jun 26, 2017 at 18:43
  • In the config file where you define the virtual host for your domain. That might be in a sites-available/ or in your conf.d/ - I don't know. Commented Jun 26, 2017 at 18:44
  • Excuse my ignorance, but do I add it to a .config file in .ebextensions, so that at deploy time it is added to a .conf file? e.g. in my example above, add it to the .ebextensions/myapp.config file? Commented Jun 26, 2017 at 18:46
  • I'm similarly ignorant, I know Apache httpd, but I don't know what .ebextensions does... :( Commented Jun 26, 2017 at 18:51
  • .ebextensions is a directory you add to your app root at build time, and when you deploy Tomcat, the commands are executed before the server starts. Commented Jun 26, 2017 at 18:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.