关于域名配置。fecshop提供的方式是这样的。在store中配置store=>stores
'appserver.fecshoptest.com'=>[]
nginx配置大致如下:
server {
listen 80;
server_name appserver.fecshoptest.com;
root /usr/share/nginx/html/fecshop/appserver/web;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9100;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
现在域名形式需要改成这样的: www.fecshoptest.com/appsever 修改nginx中配置如下:
server {
listen 80;
server_name appserver.fecshoptest.com;
root /usr/share/nginx/html;
location ^~ /appserver {
try_files $uri $uri/ /appserver/web/index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9100;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
然后将store配置修改为:
'www.fecshoptest.com'=>[],
'www.fecshoptest.com/appserver'=>[]
发现报错:
An Error occurred while handling another error:
exception 'ReflectionException' with message 'Method fecshop\services\Store::bootstrap() does not exist' in /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php:195
Stack trace:
#0 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(195): ReflectionMethod->__construct('fecshop\\service...', 'bootstrap')
#1 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php(26): yii\web\ErrorHandler->addTypeLinks('fecshop\\service...')
#2 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/View.php(330): require('/usr/share/ngin...')
#3 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/View.php(250): yii\base\View->renderPhpFile('/usr/share/ngin...', Array)
#4 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(249): yii\base\View->renderFile('@yii/views/erro...', Array, Object(yii\web\ErrorHandler))
#5 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(304): yii\web\ErrorHandler->renderFile('@yii/views/erro...', Array)
#6 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(326): yii\web\ErrorHandler->renderCallStackItem('/usr/share/ngin...', 23, 'fecshop\\service...', 'bootstrap', Array, 5)
#7 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/views/errorHandler/exception.php(381): yii\web\ErrorHandler->renderCallStack(Object(yii\base\InvalidValueException))
#8 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/View.php(330): require('/usr/share/ngin...')
#9 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/View.php(250): yii\base\View->renderPhpFile('/usr/share/ngin...', Array)
#10 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(249): yii\base\View->renderFile('@yii/views/erro...', Array, Object(yii\web\ErrorHandler))
#11 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/ErrorHandler.php(116): yii\web\ErrorHandler->renderFile('@yii/views/erro...', Array)
#12 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\base\InvalidValueException))
#13 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\InvalidValueException))
#14 {main}
Previous exception:
exception 'yii\base\InvalidValueException' with message 'this domain is not config in store component' in /usr/share/nginx/html/fecshop/vendor/fancyecommerce/fecshop/services/Store.php:165
Stack trace:
#0 [internal function]: fecshop\services\Store->actionBootstrap(Object(yii\web\Application))
#1 /usr/share/nginx/html/fecshop/vendor/fancyecommerce/fecshop/services/Service.php(49): call_user_func_array(Array, Array)
#2 /usr/share/nginx/html/fecshop/vendor/fancyecommerce/fecshop/components/Store.php(23): fecshop\services\Service->__call('bootstrap', Array)
#3 /usr/share/nginx/html/fecshop/vendor/fancyecommerce/fecshop/components/Store.php(23): fecshop\services\Store->bootstrap(Object(yii\web\Application))
#4 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/Application.php(320): fecshop\components\Store->bootstrap(Object(yii\web\Application))
#5 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/web/Application.php(69): yii\base\Application->bootstrap()
#6 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/Application.php(272): yii\web\Application->bootstrap()
#7 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/Object.php(107): yii\base\Application->init()
#8 /usr/share/nginx/html/fecshop/vendor/yiisoft/yii2/base/Application.php(205): yii\base\Object->__construct(Array)
#9 /usr/share/nginx/html/fecshop/appserver/web/index.php(83): yii\base\Application->__construct(Array)
#10 {main}
有什么比较好的方式可以支持我所需要的配置方式: 域名/项目 如:xxx.com/appserver xxx.com/image xxx.com/appfront 。谢谢。
可以的
1.nginx 配置,将 www.xxx.com 指向 @app/web目录
2.store配置:
参考:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_store.html
'stores' => [
# store key:域名去掉http部分,作为key,这个必须这样定义。
'www.xxx.com/appserver' => [
'language' => 'en_US',
注意:store key是域名+appserver
,也就是:www.xxx.com/appserver
3.需要去@app/web 路径下面新建一个文件夹appserver
,进入这个文件夹,添加文件夹 @app/web/appserver/assets
和index.php文件
@app/web/appserver/index.php
注意: @app/web/appserver/assets
要设置可写
index.php的内容复制@app/web/index.php
,然后将里面的文件路径改改,譬如将
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/fancyecommerce/fecshop/yii/Yii.php');
改成
require(__DIR__ . '/../../../vendor/autoload.php');
require(__DIR__ . '/../../../vendor/fancyecommerce/fecshop/yii/Yii.php');
因为文件夹的路径不同,因此需要加一个 /..
,
你不用自己更改了,直接复制我下面的内容添加到@app/web/appserver/index.php
即可。
<?php
error_reporting(E_ALL || ~E_NOTICE); //除去 E_NOTICE 之外的所有错误信息
#ini_set('session.cookie_domain', '.fancyecommerce.com'); //初始化域名,
$http = ($_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
$homeUrl = $http.'://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/');
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../../vendor/autoload.php');
require(__DIR__ . '/../../../vendor/fancyecommerce/fecshop/yii/Yii.php');
require(__DIR__ . '/../../../common/config/bootstrap.php');
require(__DIR__ . '/../../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
# fecshop services config
require(__DIR__ . '/../../../vendor/fancyecommerce/fecshop/config/fecshop.php'),
# fecshop module config
require(__DIR__ . '/../../../vendor/fancyecommerce/fecshop/app/appfront/config/appfront.php'),
# thrid part confing
# common modules and services.
require(__DIR__ . '/../../../common/config/fecshop_local.php'),
# appadmin local modules and services.
require(__DIR__ . '/../../config/fecshop_local.php')
);
$config['homeUrl'] = $homeUrl;
/**
* yii class Map Custom
*/
$yiiClassMap = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/YiiClassMap.php'),
require(__DIR__ . '/../../../common/config/YiiClassMap.php')
);
if(is_array($yiiClassMap) && !empty($yiiClassMap)){
foreach($yiiClassMap as $namespace => $filePath){
Yii::$classMap[$namespace] = $filePath;
}
}
/**
* Yii 重写block controller model等
* 也就是说:除了compoent 和services,其他的用RewriteMap的方式来实现重写
* 重写的类可以集成被重写的类
*/
$yiiRewriteMap = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/YiiRewriteMap.php'),
require(__DIR__ . '/../../../common/config/YiiRewriteMap.php')
);
if(is_array($yiiRewriteMap) && !empty($yiiRewriteMap)){
Yii::$rewriteMap = $yiiRewriteMap;
}
/**
* 添加fecshop的服务 ,Yii::$service , 将services的配置添加到这个对象。
* 使用方法:Yii::$service->cms->article;
* 上面的例子就是获取cms服务的子服务article。
*/
new fecshop\services\Application($config['services']);
unset($config['services']);
$application = new yii\web\Application($config);
$application->run();
你想要的这个,其实就是fecshop多语言两种方式中的一种,譬如: https://fecshop.appfront.fancyecommerce.com/fr/
fecshop多语言分为2种实现方式
1.子域名的方式 www.xx.com fr.xx.com es.xx.com
2.后缀的方式 www.xx.com/fr www.xx.com/es
你可以安装后,参考一下里面的fr的实现,吧https://fecshop.appfront.fancyecommerce.com/fr/ 实现出来,里面相应的代码都写好了,你直接nginx配置就行, 这种配置好后,你自然就明白原理。