Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

静态资源加载失败 #317

Closed
fcwys opened this issue Mar 13, 2022 · 13 comments
Closed

静态资源加载失败 #317

fcwys opened this issue Mar 13, 2022 · 13 comments

Comments

@fcwys
Copy link

fcwys commented Mar 13, 2022

image

@wisp-x
Copy link
Collaborator

wisp-x commented Mar 13, 2022

请求域名是反代的吗?

@fcwys
Copy link
Author

fcwys commented Mar 13, 2022

用了CDN,不是反代,直接本地hosts映射,HTTPS正常,加上CDN就不行

@wisp-x
Copy link
Collaborator

wisp-x commented Mar 13, 2022

应该是 cdn 的问题,估计与 cdn 返回的 headers 有关,但是你可以强行指定静态资源域名,编辑 .env 文件,追加一行:

ASSET_URL=https://你的域名

@fcwys
Copy link
Author

fcwys commented Mar 13, 2022

好的,我试试

@fcwys
Copy link
Author

fcwys commented Mar 13, 2022

界面正常了,但是图片加载失败
image

@wisp-x
Copy link
Collaborator

wisp-x commented Mar 13, 2022

忘了...静态资源变成 https 了,但是接口域名还是 http 的。那你只能修改代码了。
在这个文件的 boot 方法里

public function boot()
{
// 是否需要生成 env 文件
if (! file_exists(base_path('.env'))) {
file_put_contents(base_path('.env'), file_get_contents(base_path('.env.example')));
// 生成 key
Artisan::call('key:generate');
}
// 如果已经安装程序,初始化一些配置
if (file_exists(base_path('installed.lock'))) {
// 覆盖默认配置
Config::set('app.name', Utils::config(ConfigKey::AppName));
Config::set('mail', array_merge(\config('mail'), Utils::config(ConfigKey::Mail)->toArray()));
View::composer('*', function (\Illuminate\View\View $view) {
/** @var Group $group */
$group = Auth::check() ? Auth::user()->group : Group::query()->where('is_guest', true)->first();
$view->with('_group', $group);
});
}
}

第 32 行下面追加一行:
\Illuminate\Support\Facades\URL::forceScheme('https');

@fcwys
Copy link
Author

fcwys commented Mar 13, 2022

好的,谢谢

@fcwys
Copy link
Author

fcwys commented Mar 13, 2022

经过测试可以了,希望下个版本修复下呢,辛苦!

@Soulballad
Copy link

忘了...静态资源变成 https 了,但是接口域名还是 http 的。那你只能修改代码了。 在这个文件的 boot 方法里

public function boot()
{
// 是否需要生成 env 文件
if (! file_exists(base_path('.env'))) {
file_put_contents(base_path('.env'), file_get_contents(base_path('.env.example')));
// 生成 key
Artisan::call('key:generate');
}
// 如果已经安装程序,初始化一些配置
if (file_exists(base_path('installed.lock'))) {
// 覆盖默认配置
Config::set('app.name', Utils::config(ConfigKey::AppName));
Config::set('mail', array_merge(\config('mail'), Utils::config(ConfigKey::Mail)->toArray()));
View::composer('*', function (\Illuminate\View\View $view) {
/** @var Group $group */
$group = Auth::check() ? Auth::user()->group : Group::query()->where('is_guest', true)->first();
$view->with('_group', $group);
});
}
}

第 32 行下面追加一行: \Illuminate\Support\Facades\URL::forceScheme('https');

我也遇到了跨域问题,使用此方法解决了

@leoneoo
Copy link

leoneoo commented Nov 12, 2022

我是设置了反向代理后,https访问后,网页无法正常浏览,使用此方法设置后,https访问正常了。感谢!!!

@hausen1012
Copy link

bug还没解决吗?

@zhaoguo2008
Copy link

我添加代码,但是没有反应,登陆还是乱的

@everfu
Copy link

everfu commented Jul 28, 2023

请问我有两个域名能够同时添加吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@zhaoguo2008 @Soulballad @wisp-x @fcwys @hausen1012 @everfu @leoneoo and others