问题
我正在通过从 laravel 复制和粘贴的 laravel 'temporarySignedRoute' 函数创建签名 URL signed routes文档,在我的网络服务器上,url 出现 403 无效签名。签名的 URL 在我的本地机器上工作,但在将它上传到我的测试服务器时,它给出了如下所示的错误。
我试过的
我一直在寻找解决方案一段时间,并尝试了许多已发布在堆栈溢出上的解决方案,但似乎没有任何解决方案可以解决我的问题。
我已经尝试了以下所有方法:
- 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);
}
本地项目
主持项目
所以 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/