swoole-foundation / yii2-swoole-extension

running yii2 app on swoole
MIT License
41 stars 5 forks source link

Advanced Template #5

Open budipratama opened 3 years ago

budipratama commented 3 years ago

I have invalid route when use template advanced with use controllerNamespace like bellow :

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
//    'controllerNamespace' => 'tests\controllers',
    'taskNamespace' => 'tests\tasks',
   .......
];
```php

HTTP/1.1 404 Not Found Content-Type: application/json; charset=UTF-8 Server: swoole-http-server Connection: keep-alive Date: Tue, 16 Feb 2021 19:41:13 GMT Content-Length: 246

{"name":"Not Found","message":"Page not found.","code":0,"status":404,"type":"yii\web\NotFoundHttpException","previous":{"name":"Invalid Route","message":"Unable to resolve the request \"\".","code":0,"type":"yii\base\InvalidRouteException"}}

tiagocomti commented 3 years ago

I had same here.

[[A2021-03-07 00:14:27 [10.69.64.29][-][-][error][yii\web\HttpException:404] yii\base\InvalidRouteException: Unable to resolve the request "index.php". in PATHvendor/yiisoft/yii2/base/Module.php:543

xialeistudio commented 3 years ago

Can you submit a minimal project at github and share it to me? I'll check your code

tiagocomti commented 3 years ago

Can you submit a minimal project at github and share it to me? I'll check your code

sure! https://github.com/FogoQueima/advancedyii2-swoole/tree/master

tiagocomti commented 3 years ago

server { listen 65450 default; root /usr/local/www/testeswoole/advanced/frontend/web; index index.php index.html; client_max_body_size 500m; charset utf-8; location / {

Redirect everything that isn't a real file to index.php

         try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:9500;
}

}

My nginx.conf. maybe the problem is here

BaBL86 commented 1 year ago

Use the full frontend config

My frontend/config/swoole.php

<?php
require __DIR__ . '/../../common/config/bootstrap.php';
require __DIR__ . '/bootstrap.php';

$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/../../common/config/main.php',
require __DIR__ . '/../../common/config/main-local.php',
require __DIR__ . '/main.php',
require __DIR__ . '/main-local.php'
);

$config['components']['response']['class'] = swoole\foundation\web\Response::class;
$config['components']['request']['class'] = swoole\foundation\web\Request::class;
$config['components']['errorHandler']['class'] = swoole\foundation\web\ErrorHandler::class;

return $config;