2
2

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 3 years have passed since last update.

laravel開発サイトにngrok経由で接続する際にhttps固定にする

Posted at

ローカル開発中のlaravelで内蔵サーバ (php artisan serve) を起動し一時的な確認のためにngrok経由で接続する際、httpsで接続してもhttp接続に切り替わってしまいました。https接続固定にする設定をおこなったのでメモ。

###私の環境

  • macOS Catalina
  • PHP 7.4.8
  • Laravel 6.18.8
  • ngrok 2.3.35

###設定

laravelディレクトリ内で以下ファイルを設定

.env
...
APP_ENV=dev_ngrok
...
APP_URL=http://127.0.0.1:8000
...
app/Providers/AppServiceProvider.php
public function boot()
{
    //.envファイルで APP_ENV=dev_ngrok の際に適用される
    if(env('APP_ENV') === 'dev_ngrok')
    {
        $this->app['request']->server->set('HTTPS', true);
    }
}

###サーバ起動

####Laravelローカルサーバ起動

php artisan serve --host=127.0.0.1 --port=8000

####ngrok起動

ngrok http 127.0.0.1:8000
Session Status                online                                                                        
...                                                       
Forwarding                    http://*********.ngrok.io -> http://127.0.0.1:8001                         
Forwarding                    https://*********.ngrok.io -> http://127.0.0.1:8001 
...

となるので https://*********.ngrok.io に接続するとhttpsで接続される

###参考文献

https://stackoverflow.com/questions/60407010/unsupported-ssl-request-php-artisan-serve

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?