【问题标题】:temporary signed url always expired laravel临时签名的 url 总是过期 laravel
【发布时间】:2020-03-20 08:22:03
【问题描述】:

将 Laravel 5.7 应用程序移植到 Docker 后,临时签名的 URL 始终处于过期状态

函数看起来像

public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('2FA Reset Confirmation')
            ->view('emails.confirmReset2fa',[
                'link' => URL::temporarySignedRoute(
                    '2fa.reset.confirm', now()->addMinutes(30), ['user' => $this->resetUser->id]
                )
            ]);

在容器 nginx 内部,配置了 php-fpm 和应用程序本身。容器位于 traefik 后面

【问题讨论】:

  • 生成链接到签名 url 的 html 示例?我会担心添加了点击标识符或类似内容。
  • @mrhn 感谢您的关注!问题解决了;)

标签: laravel docker


【解决方案1】:

所以,我解决了我的问题。 问题出在负载均衡器和下一个代码上,我添加了这些代码来强制使用 HTTPS。

if (env('APP_ENV') == 'prod' or env('APP_ENV') == 'dev') {
    \URL::forceScheme('https');
}

我需要添加app/Http/Middleware/TrustProxies.php

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var string
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

https://laravel.com/docs/5.8/requests#configuring-trusted-proxies

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多