gpt4 book ai didi

php - 使用 nginx 的每条路由上的 NotFoundHttpException

转载 作者:行者123 更新时间:2023-12-04 18:46:22 25 4
gpt4 key购买 nike

我尝试将 nginx 配置为动态处理对 laravel 应用程序的所有/{{app}}/query 请求,如下所示:

server {
listen 80;
server_name localhost;
root /usr/share/nginx/apps;

location / {
index index.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^/([^/]+)(.*)$ /$1/public/index.php?$2 last;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

目前 nginx 将我的请求路由到正确的目录和文件。例如:
www.domain.com/test/item/1/edit

...路线:
/path/to/my/apps/test/public/index.php?/item/1/edit

我还能够回显 var_export($_GET) 并查看该查询:
array(
'/item/1/edit' => '',
)

但 Laravel 总是说:
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 823
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 57

但为什么?

路线如下所示:
Route::get('/', function () {
return view('welcome');
});

Route::get('/item', function() {
return 'Item';
});

php artisan route:list 返回:
+--------+----------+---------+------+---------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+---------+------+---------+------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | item | | Closure | web |
+--------+----------+---------+------+---------+------------+

我的 Laravel 版本是 5.2.33
我使用带有 PHP 7.0.6 (PHP-FPM) 作为主机的 Ubuntu 16.04 服务器。

是 nginx 配置问题吗?
还是 Laravel 的问题?
或者它是一个Linux,也许是权限相关的主题?

最佳答案

将应用程序根目录指向公用文件夹,它将起作用

关于php - 使用 nginx 的每条路由上的 NotFoundHttpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37466924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com