laravel 网络路由 return 404(找不到控制器)
laravel web route return 404 (cant find controller)
我在互联网上看到过很多关于我遇到的问题,但它们都很广泛,很难准确指出问题出在哪里,因为它可能有很多变数,所以我决定列出所有内容我试过了,也许有人可以帮助我。
URL 正在尝试访问
控制器
目录app/Http/Controllers/DirManagements/GetDirs.php
namespace App\Http\Controllers\DirManagements;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class GetDirs extends Controller
{
public function __construct()
{
}
public function getResult()
{
echo "hi";
}
}
网络路由
Route::get('dirs', 'DirManagements\GetDirs@getResult');
PHP artisan route:list
Domain | Method | URI | Name | Action | Middleware
| |GET|HEAD | dirs | | App\Http\Controllers\DirManagements\GetDirs@getResult | web
Nginx Sites-available 文件
server {
listen 443 ssl;
root /my-dir-to-web;
index index.php index.phtml index.html index.htm index.nginx-debian.html;
server_name mysub.mySite.dev;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
ssl_certificate /etc/letsencrypt/live/something/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/something/privkey.pem; # managed by Certbot
}
解决方案
我不知道为什么 laravel 在设置 laravel 时没有将其包含在他们的安装文档中。将它添加到我的 nginx 配置中并且它起作用了。
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
可能有多种原因会导致此问题。尝试以下各项,让我知道是否有效:
- 确保您在创建路由后重新启动了服务器。
确保您有 运行 以下命令,以免出现任何类型的缓存问题:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear
我在互联网上看到过很多关于我遇到的问题,但它们都很广泛,很难准确指出问题出在哪里,因为它可能有很多变数,所以我决定列出所有内容我试过了,也许有人可以帮助我。
URL 正在尝试访问
控制器
目录app/Http/Controllers/DirManagements/GetDirs.php
namespace App\Http\Controllers\DirManagements;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class GetDirs extends Controller
{
public function __construct()
{
}
public function getResult()
{
echo "hi";
}
}
网络路由
Route::get('dirs', 'DirManagements\GetDirs@getResult');
PHP artisan route:list
Domain | Method | URI | Name | Action | Middleware
| |GET|HEAD | dirs | | App\Http\Controllers\DirManagements\GetDirs@getResult | web
Nginx Sites-available 文件
server {
listen 443 ssl;
root /my-dir-to-web;
index index.php index.phtml index.html index.htm index.nginx-debian.html;
server_name mysub.mySite.dev;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
ssl_certificate /etc/letsencrypt/live/something/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/something/privkey.pem; # managed by Certbot
}
解决方案
我不知道为什么 laravel 在设置 laravel 时没有将其包含在他们的安装文档中。将它添加到我的 nginx 配置中并且它起作用了。
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
可能有多种原因会导致此问题。尝试以下各项,让我知道是否有效:
- 确保您在创建路由后重新启动了服务器。
确保您有 运行 以下命令,以免出现任何类型的缓存问题:
php artisan config:clear php artisan cache:clear composer dump-autoload php artisan view:clear php artisan route:clear