11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel 5.5 にてロードバランサ配下のアプリケーションにHTTPS通信を適用させる

Last updated at Posted at 2018-03-07

前提

案件でLaravelを使っており、開発サーバー上でのURL生成をhttpsにしたいのにもかかわらず、httpになっていたので、解決策を調べていました。

結論

ここ見ておけばOKでした。

手順まとめ

  • App\Http\Middleware\TrustProxies を使う
  • TrustProxies.php を編集する

以上!

コードの編集

  • protected $proxies = '**';にする

理由はAWS等を使うとIPがわからないため。IPが分かる場合はここを編集しましょう

TrustProxies.php
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */

    protected $proxies = '**'; 



    /**
     * The current proxy header mappings.
     *
     * @var array
     */
    protected $headers = [
        Request::HEADER_FORWARDED => 'FORWARDED',
        Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
        Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
        Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
        Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
    ];
}
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?