paiza cloud의 HTTPS 제한에 푹 빠졌어요.

4788 단어 paizacloudPHPLaravel

개요

PaizaCloud를 사용하면 개발 환경을 간단하게 구축할 수 있다.유료 방안이라면 언제든 공개할 수 있다.
https://paiza.cloud/ja/
PaizaCloud를 이용하여 Laavel 학습용 개발 환경 구축
HTTPS 주변 일에 걸려 넘어져서 초보자는 반할 수밖에 없기 때문에 누군가가 어려움에 처했을 때 참고할 수 있도록 필기를 한다.

자세하다

php artisan make:auth  // ログイン認証画面を作成
php artisan migrate    // DBに反映
php artisan serve --host=0.0.0.0
이렇게 하면 로그인 화면이 나온다. 방문xxx.paiza-user.cloud:8000.

단, 오른쪽 상단LOGIN을 눌러도Please use HTTPS(SSL) instead of HTTP to access the URL.표시, 로그인 화면이 표시되지 않음...
만약 현지 환경이라면 잘 보일 것이다. 왜냐하면...

왜 그랬을까

  • 로그인 화면에 대한 링크http
  • 첫 페이지가 https에 표시되어 있어서 당연하다고 생각했다https 링크http는 눈치채지 못했다...
  • Paiza Cloud에서 비 SSL 액세스가 있는 경우
  • 해결책


    [댓글 접수 및 추가]
    여기가 https가 되지 않는 것은, XFORWARDED_PROTO를 사용하여 판정을 내리지 않았기 때문입니다.
    app/Http/Middleware/TrustProxies.php
    // 略
    class TrustProxies extends Middleware
    {
        /**
         * The trusted proxies for this application.
         *
         * @var array|string
         */
        protected $proxies = "*"; // ここに"*"を指定する
    
        /**
         * The headers that should be used to detect proxies.
         *
         * @var int
         */
        protected $headers = Request::HEADER_X_FORWARDED_ALL;
    }
    
    
    이 보도에는 상세한 해설이 있다.
    https://qiita.com/yamatox/items/8f3f481d88e807793ad5
    다음은 forceScheme을 사용하는 방법입니다.이 방법에서 처리된 URL을 https로 강제합니다.
    AppServiceProvider boot 방법을 사용하여 UrlGener 클래스forceScheme 메서드 호출
    응용 프로그램 내에서 처리되는 URL을 모두 https로 설정합니다.
    이렇게 하면 링크는https로 출력됩니다.
    app/Providers/AppServiceProvider.php
    <?php
    
    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    use Illuminate\Routing\UrlGenerator;
    
    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {
            //
        }
    
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot(UrlGenerator $url)
        {
            // force to use HTTPS
            $url->forceScheme('https');
        }
    }
    

    참고 자료


    [Laavel] 항상 SSL 응용 프로그램에서 URL을 생성하는 모범 사례를 고려합니다.
    https://qiita.com/hisash/items/4b3bb1ea47c38b0d8c86

    좋은 웹페이지 즐겨찾기