php - Laravel 403 无效签名仅在 Nginx Web 服务器上

标签 php laravel nginx https

问题

我正在通过从 laravel 复制和粘贴的 laravel 'temporarySignedRoute' 函数创建签名 URL signed routes文档,在我的网络服务器上,url 出现 403 无效签名。签名的 URL 在我的本地机器上工作,但在将它上传到我的测试服务器时,它给出了如下所示的错误。

enter image description here

我试过的

我一直在寻找解决方案一段时间,并尝试了许多已发布在堆栈溢出上的解决方案,但似乎没有任何解决方案可以解决我的问题。

我已经尝试了以下所有方法:

  • Forcing all routes to https through the AppServiceProvider, this forced all of the url's to be https but gave the same result.
  • I tried changing Nginx's configuration as described here.

  • I also tried adding the TrustProxies middleware with the proxies configured to '*' or all, like described in laravel's documentation on Trust Proxies, same result.

  • Stopped the web server from forcing the domain to https to test if it was just https causing it, same result.



- 更新 -

我进入vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php在尝试四处寻找项目中的任何线索时。我决定数据转储 (dd) 出它在我的本地和托管项目上比较的 token ,这就是结果。代码如下所示。
public function hasValidSignature(Request $request, $absolute = true)
{
    $url = $absolute ? $request->url() : '/'.$request->path();

    $original = rtrim($url.'?'.Arr::query(
        Arr::except($request->query(), 'signature')
    ), '?');

    $expires = $request->query('expires');

    $signature = hash_hmac('sha256', $original, call_user_func($this->keyResolver));
    dd($signature . " :: " . $request->query('signature', ''));
    return  hash_equals($signature, (string) $request->query('signature', '')) &&
           ! ($expires && Carbon::now()->getTimestamp() > $expires);
}

本地项目

local project

主持项目

remote machine

所以 token 没有在我的网络服务器上传递,而是在我的本地。另外我注意到的另一件事是网络服务器 token 始终相同并且无论如何都不会改变。

我目前的Nginx配置可以查看here .

我当前的虚拟主机配置是 here .

最佳答案

我想这可能是问题所在。
尝试将配置文件中的位置块更改为
try_files $uri $uri/ /index.php?$query_string;
我想你已经错过了 ?之间索引和查询字符串 .

更新它并确保重新加载您的 Nginx 服务器。sudo service nginx reload
让我知道这个是否奏效。

关于php - Laravel 403 无效签名仅在 Nginx Web 服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56704971/

相关文章:

php - 如何修复 PHP 中格式错误的 URL?

PHP include 包含在 include 中(不同的目录)

php - 在数据库中插入单选按钮输入

php - Laravel SQL 通过网络连接错误,在 artisan 中工作

nginx - 使用 ffmpeg 在 nginx 上将 rtsp 转换为 rtmp

reactjs - 无法使用React将nginx代理设置为Docker容器

performance - 将网络延迟从 500 毫秒减少到 60-100 毫秒的策略

php - 我应该学习 mysqli 还是 PDO?

javascript - React CRUD 应用程序中出现错误 : TypeError: Cannot destructure property 'id' of 'this.props.event' as it is undefined

php - 如何以编程方式登录然后使用 Laravel 5.5 重定向?