【发布时间】:2016-03-18 02:34:47
【问题描述】:
我最近将 Laravel API 部署到 AWS ElasticBeanStalk。
我想测试 API 是否正在运行,所以我做了一个简单的路由来返回一条消息。在本地,它工作正常:
输出:Welcome
但在 AWS 上,我得到:
http://my-api.elasticbeanstalk.com/
输出:Whoops, looks like something went wrong.(输出两次)
这是一个 500 错误,没有太多其他有用的信息。
我打开调试模式得到:
RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid.
查了这个错误,发现this,说把我的config\app.php密码改成:
'cipher' => 'AES-256-CBC',
但它已经是那个值了。
然后它说要确保 .env APP_KEY 是 32 位,我的也是。
localhost 和 aws 应用程序之间的请求标头看起来相似。存在差异,但我认为没有一个会返回 500。我通过 SSH 连接到 AWS EC2 以验证路由是否相同。
路线:
Route::group(['middleware' => 'cors'], function(Router $router) {
Route::get('/', function () {
return 'Welcome';
});
class EncryptionServiceProvider extends ServiceProvider
{
Encryption Service Provider:
public function register()
{
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');
$key = $config['key'];
$cipher = $config['cipher'];
if (Encrypter::supported($key, $cipher)) {
return new Encrypter($key, $cipher);
} elseif (McryptEncrypter::supported($key, $cipher)) {
return new McryptEncrypter($key, $cipher);
} else {
throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
}
});
}
【问题讨论】:
-
您的服务器上应该有一个错误日志。我会寻找它而不是试图猜测问题可能是什么。
标签: php api amazon-web-services