【问题标题】:AWS API routes returning 500AWS API 路由返回 500
【发布时间】:2016-03-18 02:34:47
【问题描述】:

我最近将 Laravel API 部署到 AWS ElasticBeanStalk。

我想测试 API 是否正在运行,所以我做了一个简单的路由来返回一条消息。在本地,它工作正常:

http://my-api.localhost/

输出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


【解决方案1】:

糟糕,忘记将 ENV 变量添加到 AWS 应用实例。

1) 进入应用->配置->软件配置

2) 在本地 .env 中添加环境变量并为生产指定唯一值

3) 通过 SSH 连接到服务器,验证 ENV 变量是否已在 EC2 上注册,然后 cd /opt/elasticbeanstalk/support 并运行 cat envvars。应列出 ENV 变量。

4) 然后使用source envvars 执行envvars

5) 输出 ENV 变量以验证它们是否已在应用程序中设置:echo env $APP_KEY 将输出您设置的 ENV

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 2017-12-13
    • 1970-01-01
    • 2020-09-11
    • 2018-04-10
    相关资源
    最近更新 更多