Laravel5 で httpsサイトを作る方法。および、Cloud9の80ポート問題解決法
In developing larvel application At cloud9,
Port 80 problem is often coming out.
■Cloud9 adds port 80 to Laravel route
https://community.c9.io/t/cloud9-adds-port-80-to-laravel-route/475
Well I do not know, but I tried to do in various ways,
It happens in following two conditions.
- Current page address is “http://…"
- You pressed the link that is written in the relative path ()<a href="/…")
Basically address is “https://…" at cloud9,
but laravel generate the full path link (<a href="http://…") by default,
we are “http://.." address unwittingly, and error is occured
So, It’s OK to keep address “https://…".
The following is a solution.
■Laravel 5 – redirect to HTTPS
http://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https
There are two files to modify.
# /app/Http/Middleware/ForceHttps.php
https://github.com/dog-ears/force_https_on_laravel/blob/master/app/Http/Middleware/ForceHttps.php
public function handle($request, Closure $next) { // if (!app()->environment('local')) { // for Proxies Request::setTrustedProxies([$request->getClientIp()]); if (!$request->isSecure()) { return redirect()->secure($request->getRequestUri()); } // } return $next($request); }
Function to determine in the environment has been commented out ,so for the time being unnecessary,
Basically, It checks $request is whether sequre(https://…) or not,
If not https, to change to https. That’s all.
However,specification on, When it flew request at https,
$request->isSecure()
To those described above, It return false.
And it will be permanent loop in this state.
(For more information on here, currently unknown. I guess proxy issues…)
Therefore, to add a sentence below.
Request::setTrustedProxies([$request->getClientIp()]);
It’s mean to tell the system “Client IP is a reliable proxy".
# /app/Http/Kernel.php
https://github.com/dog-ears/force_https_on_laravel/blob/master/app/Http/Kernel.php
Add the following sentence to $middleware.
\App\Http\Middleware\ForceHttps::class,
Now, http → https is applied to all routes,Port80 problem should not occur.
Try it.
Thank you.
Discussion
New Comments
No comments yet. Be the first one!