Laravel Admin 包的一些问题
Closed this issue · 10 comments
该包Laravel Admin的 302 跳转请求不生效,
例如增加菜单项, 提交成功后会进行跳转, 控制台打印到了该请求, 但是没有后续反应
[2020-06-19 16:15:46] 127.0.0.1 [302]: POST http://a.work.test/backend/auth/menu [83.28ms]
数据清理监听器: 按照 Laravel-S
<?php
namespace App\Listeners;
use Encore\Admin\Admin;
use HuangYi\Shadowfax\Events\AppPushingEvent;
use Illuminate\Support\Facades\Facade;
class RebindLaravelAdmin
{
public const ADMIN_CLASS = Admin::class;
protected $properties = [
'deferredScript' => [],
'script' => [],
'style' => [],
'css' => [],
'js' => [],
'html' => [],
'headerJs' => [],
'manifestData' => [],
'extensions' => [],
'minifyIgnores' => [],
];
/**
* Handle the event.
*
* @param AppPushingEvent $event
*
* @return void
*/
public function handle(AppPushingEvent $event) : void
{
$reflection = new \ReflectionClass(self::ADMIN_CLASS);
foreach ($this->properties as $name => $value) {
if (property_exists(self::ADMIN_CLASS, $name)) {
$reflection->setStaticPropertyValue($name, $value);
}
}
$event->app->forgetInstance(self::ADMIN_CLASS);
Facade::clearResolvedInstance(self::ADMIN_CLASS);
}
}
302是浏览器行为,主要观察Response里的Location值。我看你打印出来的响应已经是302了,应该没问题啊。
是的,
在提交后, 保存成功, 控制台可以打印出302请求, 但是之后就没有了. 页面也没有按照逻辑返回到上一页页面.
难道是我nginx配置问题吗? 感觉这里和nginx应该没有太大关系.
我的意思是:你可以用浏览器的调试工具,观察一下http://a.work.test/backend/auth/menu
请求的status code是不是302,然后Response头里面有没有携带Location信息。
我特意安装了laravel-admin测试了下,里面的302跳转都正常,没发现什么问题
我特意安装了laravel-admin测试了下,里面的302跳转都正常,没发现什么问题
如果全站走 https
呢? 我本地 302 无反应是因为部分 laravel admin
的链接是 http
.
如: 列表页面地址是 https
, 创建页面地址是 https
, 但是提交表单的地址是 http
.
下面是本地项目中的 https
配置.
AppServiceProvider.php
public function boot() : void
{
URL::forceScheme('https');
}
admin.php
'https' => env('ADMIN_HTTPS', true),
app.php
'url' => env('APP_URL', 'https://a.work.test'),
'asset_url' => env('ASSET_URL', 'https://a.work.test'),
PHP-FPM
下是正常的. 所有的链接都是 https
, 但是在启动 php shadowfax start
后, laravel admin
页面生成的部分链接就会是 http
的.
HTTPS的问题好办,只要保证trustedproxies设置正确(shadowfax监听的IP务必设置进去),并且nginx里面设置好这个proxy_set_header X-Forwarded-Proto $scheme;
就行。
HTTPS的问题好办,只要保证trustedproxies设置正确(shadowfax监听的IP务必设置进去),并且nginx里面设置好这个
proxy_set_header X-Forwarded-Proto $scheme;
就行。
现在本地项目中的关于您说的这两个配置,如下:
config/trustedproxies.php
'proxies' => ['127.0.0.1'],
'headers' => Request::HEADER_X_FORWARDED_ALL,
nginx.conf
location @shadowfax {
set $suffix "";
if ($uri = /index.php) {
set $suffix ?$query_string;
}
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Scheme $scheme;
proxy_set_header Server-Protocol $server_protocol;
proxy_set_header Server-Name $server_name;
proxy_set_header Server-Addr $server_addr;
proxy_set_header Server-Port $server_port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Uncomment this if you are running a websocket server.
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1:1215$suffix;
}
我看你之前的访问日志都是https的,但这次这个打印出来的http,所以估计是trustedproxies配置的问题,你改成用配置文件来控制trustedproxies的话,TrustedProxies中间件里面的$proxies
属性就不能设置值了,因为$proxies
属性的优先级高
HTTPS的问题好办,只要保证trustedproxies设置正确(shadowfax监听的IP务必设置进去),并且nginx里面设置好这个
proxy_set_header X-Forwarded-Proto $scheme;
就行。
我应该是找到错误的地方了. TrustProxies
中间件的优先级高于 config/trustedproxies
.
我看你之前的访问日志都是https的,但这次这个打印出来的http,所以估计是trustedproxies配置的问题,你改成用配置文件来控制trustedproxies的话,TrustedProxies中间件里面的
$proxies
属性就不能设置值了,因为$proxies
属性的优先级高
haha, 是的, 我刚发现这个问题, 我之前在 TrustedProxies
中配置了 *
.
感谢您的关注.