问题
Here is my config file
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Redirect permanent / https://www.mywebsite.co/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And when I type in the browser mywebsite.co it successfully redirects me https://mywebsite.co however content does NOT render on the page because of this error (by Google Chrome)
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
I have an EC2 instance using port 80 to handle http requests and a load balancer handling https requests. I am not sure what to do and none of the solutions I've found online are working.
回答1:
You are requesting via SSL over port 443 when you hit the ELB, but then you are requesting to the backend as insecure port 80. This is fine, but then your config has no idea that this is supposed to be over 443 because you are reverse proxying it. To the web server, this is just a port 80 insecure request, so it will try to redirect to SSL port 443, which is why it's looping.
Instead of doing a redirect, you might look at a rewrite to analyze the forwarded headers, e.g.:
RewriteEngine On
RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
RewriteRule ^(.*)$ https://www.mywebsite.co$1 [R=301,NE,L]
来源:https://stackoverflow.com/questions/37504539/how-can-i-work-around-too-many-redirects-error-when-trying-to-direct-all-web-t