本番環境でメンテナンスモードにして、特定のIPだけ操作を許可したい場合は、
$ php artisan down --allow=${ip}
と書く。EC2で実行したところ、指定したipでもメンテナンスモードの画面に。
EC2 ELB: ELBを使って、SSL対応している
ELBを挟んでいるため、ip取得のclassにHTTP_X_FORWARDED_FORを追加する
$ sudo vi vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance()) {
$data = json_decode(file_get_contents($this->app->storagePath().'/framework/down'), true);
// 追加
if (isset($data['allowed']) && IpUtils::checkIp($request->server->get('HTTP_X_FORWARDED_FOR'), (array) $data['allowed'])) {
return $next($request);
}
if (isset($data['allowed']) && IpUtils::checkIp($request->ip(), (array) $data['allowed'])) {
return $next($request);
}
if ($this->inExceptArray($request)) {
return $next($request);
}
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
}
return $next($request);
}
※HTTP_X_FORWARDED_FOR: リバースプロキシを挟んだアクセス元のIPを取得する
これで、メンテナンスモード時に、特定IPのみ操作できるようになります。
$ php artisan down –allow=${myIP}
$ php artisan up