Я работаю над приложением PHP Yii2. У меня странная проблема с yii2, вот моя проблема.yii2 и балансировка нагрузки
Как известно, существует папка Web \ активов в проекте Yii2 и она будет загружать свой собственный пакет активов, но при настройке балансировки нагрузки, я обнаружил, что инструменты разработчика консоль Хрома бросить некоторые ошибки ниже:
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/css/bootstrap.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/ebd0699a/css/AdminLTE.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/5e97633a/jquery.js Failed to load resource: the server responded with a status of 404 (Not Found)
yii.js:464 Uncaught ReferenceError: jQuery is not defined(…)
http://firekylin.eastasia.cloudapp.azure.com/assets/14e563af/yii.validation.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/js/bootstrap.js Failed to load resource: the server responded with a status of 404 (Not Found)
yii.activeForm.js:14 Uncaught TypeError: Cannot read property 'fn' of undefined(…)
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/js/bootstrap.js Failed to load resource: the server responded with a status of 404 (Not Found)
app.min.js:13 Uncaught Error: AdminLTE requires jQuery(…)
index.php:555 Uncaught ReferenceError: jQuery is not defined(…)
http://firekylin.eastasia.cloudapp.azure.com/assets/88d3a068/css/font-awesome.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/ebd0699a/css/skins/_all-skins.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
Он не может найти js, css-файл при использовании загрузочного баланса ip для посещения, но как только я использую ip сервера, на котором работает приложение Yii2, веб-страница будет успешно загружать js, css-файл:
left one is using load balance server to visit and right one is using Yii2 server to visit
Есть два сервера точно работает Yii2 и оба они имеют свою папку собственного веба \ активы и имеют различные кэша:
web\assets folders in two Yii2 servers
Я обнаружил, что когда-то я перестану один из Yii2 сервера, сервер балансировки нагрузки будет работать успешно. Поэтому я думаю, что проблема связана с папкой веб-ресурсов Yii2. Из двух приведенных выше изображений мы можем найти, что Yii2 использует md5 для переименования папок в нем, так что, возможно, это произошло из-за того, что две папки веб-ресурсов Yii2 имеют разные имена дочерних папок, из-за которых проблема возникает?
Однако, я пытаюсь решить проблему с ниже кодов:
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'defaultRoute'=>'firekylin',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => '@app/views/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
],
],
],
'assetManager' => [
'class' => 'yii\web\AssetManager',
'forceCopy' => true,
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '2MhlyGaaGs_uqt_apwy1jLahR_wZ8dBv',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
'text/json' => 'yii\web\JsonParser',
]
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\OriginUser',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
$config['components']['assetManager']['forceCopy'] = true;
}
return $config;
и
public function beforeAction($action){
Yii::$app->assetManager->forceCopy = YII_DEBUG;
return parent::beforeAction($action);
}
Я пытаюсь использовать assetManager или
$config['components']['assetManager']['forceCopy'] = true;
в конфигурации \ сети .php или function beforeAction в моем собственном контроллере, чтобы запретить папку с ресурсами, но она не работает. Есть ли способ решить проблему проблема?
Убедитесь, что путь к файлу и версия ядра yii2 одинаковы на обоих серверах. Затем очистите папку с ресурсами. –
Оба пути к файлам - var/www/prj4_firekylin/firekylin_php, и у меня есть четкие папки, но это не работает :(имена их дочерних файлов по-прежнему разные. –
Извините, моя ошибка. Это также зависит от созданного время файла. –