Based on this I added the same middleware in my app with the result of a redirect loop.
The app redirects to the login page if the user is not authenticated, so for me looks like this is the problem. Or maybe not.
The ssl certificate is installed correctly and it works (if I manually go to https://myapp.org it works as expected).
The main problem is that I use across the app the helper url() for generating urls, now I need to redirect to secure urls.
I tried removing that middleware, and adding the redirect to the .htaccess but the result is the same (this webpage has a redirect loop).
UPDATE I tried to debug the problem and looks like is not redirected to https, that's why the redirect loop. I added log for the headers....
{
"host": [
"myapp.org"
],
"accept": [
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,*\/*;q=0.8"
],
"user-agent": [
"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/41.0.2272.76 Safari\/537.36"
],
"accept-encoding": [
"gzip, deflate, sdch"
],
"accept-language": [
"en-US,en;q=0.8"
],
"cookie": [
"XSRF-TOKEN=..."
],
"x-forwarded-for": [
"IP ADDRESS"
],
"x-forwarded-host": [
"myapp.org"
],
"x-forwarded-server": [
"ip-IP.compute.internal"
],
"connection": [
"Keep-Alive"
]
}
I'm logging also the value of $request->secure()
and it's always false.
This is my middleware (the result of the log is in comment beside each log line)
<?php namespace App\Http\Middleware;
use Closure;
use Log;
class HttpsProtocol
{
/**
* Redirect to https.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if(!$request->secure() && app()->environment() === 'production') {
Log::info(app()->environment()); // "production"
Log::info($request->secure()); // ""
Log::info($request->header('x-forwarded-proto')); // ""
Log::info(json_encode($request->header())); // The json just posted
Log::info($request->getRequestUri()); // "/auth/login"
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}
My app is in Elastic Beanstalk (EC2 single-instance). Any help would be appreciated, thanks.