Laravel 7与Laradock一起投入生产:电子邮件验证403无效签名

问题描述

有很多帖子,还有StackOverflow答案,但是没有一个可以帮助我解决这个问题。

我将Laradock用于生产服务器上的Laravel应用。在Nginx和PHP 7.4上,Laravel版本是7.24.0。

但是,如果我通过mailtrap测试电子邮件验证,则会出现此错误

403 |签名无效。

我已经执行了php artisan key:generate,并且可以在我的.env文件中看到它:

APP_NAME="The cool app"
APP_ENV=production
APP_KEY=base64:S1ABrOXZ1ldmYqfjBvZfupwBNM+m10MWINqEvj/eGbg=
APP_DEBUG=true
APP_URL=https://my-domain.com

最初,Nginx的默认配置为:

server {

    listen 80;
    listen [::]:80;

    # For https
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server ipv6only=on;
    # ssl_certificate /etc/nginx/ssl/default.crt;
    # ssl_certificate_key /etc/nginx/ssl/default.key;

    server_name my-domain.com;
    root /var/www/public;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    #location /.well-known/acme-challenge/ {
    #    root /var/www/letsencrypt/;
    #    log_not_found off;
    #}
}

我也尝试过一个:

try_files $uri $uri/ /index.php?$query_string; 

如建议的here

但是什么都行不通,除非在我的本地环境中。

URL的示例是。

https://my-domain.com/email/verify/3/28d707536a36800a7cfaaaa5f5e29eca3ac2b38a?expires=1597101566&signature=2685421462a1756e38bee693801f11e2f2ed6645e3d0ad361413a758b9ca6fab

我同时选中了“验证”电子邮件按钮和Web浏览器URL,它们看起来相同。

此外,我刚刚尝试过

$ php artisan config:cache

但是没有运气:/我仍然遇到403 | Invalid signature错误

有人能对此有所启发吗?否则,如何调试呢?


已解决!赫拉(Hurra) 我已经应用了GitHub issue answered by yawmanford中的内容:

内部 AppServiceProvider.php

public function boot()
{
    if($this->app->environment('production'))
    {
        \URL::forceScheme('https');
    }
}

然后在 TrustProxies.php

protected $proxies = '*';

最后,我在workspace容器中运行:

artisan config:cache

那就成功了!

你怎么看?

解决方法

我怀疑这是您的nginx配置所致。您可以试试吗?

    try_files $uri $uri/ /index.php?$query_string;

我还看到您在应用程序中使用https,但是您的nginx配置没有SSL配置。您可以尝试在应用中使用http来查看其性能吗?

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...