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.
표시, 로그인 화면이 표시되지 않음...
만약 현지 환경이라면 잘 보일 것이다. 왜냐하면...
왜 그랬을까
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
는 눈치채지 못했다...해결책
[댓글 접수 및 추가]
여기가 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
Reference
이 문제에 관하여(paiza cloud의 HTTPS 제한에 푹 빠졌어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/akrha/items/ed415a24e3654cd67482
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
// 略
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;
}
<?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
Reference
이 문제에 관하여(paiza cloud의 HTTPS 제한에 푹 빠졌어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/akrha/items/ed415a24e3654cd67482텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)