Php 未找到Laravel-404
我最近几天才开始使用Laravel,我的Php 未找到Laravel-404,php,laravel,nginx,Php,Laravel,Nginx,我最近几天才开始使用Laravel,我的http://localhost:8017/laravel看起来不错,但http://localhost:8017/laravel/foo返回 404找不到 我的操作系统Ubuntu 16.04,Laravel 5.4 路由/web.php Route::get('/', function () { return view('welcome'); }); // oedin Route::get('foo', function () {
http://localhost:8017/laravel
看起来不错,但http://localhost:8017/laravel/foo
返回
404找不到
我的操作系统Ubuntu 16.04,Laravel 5.4
路由/web.php
Route::get('/', function () {
return view('welcome');
});
// oedin
Route::get('foo', function () {
return 'Hello World';
});
nginx配置
server {
listen 8017 default_server;
listen [::]:8017 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
#root /var/www/html;
root /home/oedin/webdev;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#try_files $uri /index.php =404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
如果您附加index.php,我想它会起作用
http://localhost:8017/laravel/index.php/foo
问题是连接到服务器,在Apache中需要类似于模式overrite的东西。在nginx中没有均衡,但尝试一下这样的东西
如果您想使用nginx为您的应用程序提供服务,建议进行新的nginx vhost配置,其中包含您的项目根文件夹 然而,使用
php artisan serve
,生活会更轻松,此时无需使用nginx服务器 您可以尝试以下方法:
Route::group(['namespace' => 'Laravel', 'prefix' => 'laravel', 'middleware' => 'laravel'], function () {
Route::get('/', function () {
return view('welcome');
});
// oedin
Route::get('foo', function () {
return 'Hello World';
});
});
您应该在终端中运行php-artisan
serv命令
your URL like http://localhost:8000/laravel/foo
希望这为你工作 这可能是由于查询错误,就像我的案例一样,试图通过错误报告显示错误,日志中没有任何内容,但我尝试在查询中捕获错误异常,得到了SQL错误 希望这有帮助, 使用try-catch语句包装要捕获异常的代码行
enter code here
try
{
//write your codes here
}
catch(Exception $e)
{
dd($e->getMessage());
}
不要忘记在控制器的顶部包含Exception类
使用例外 当你点击时,哪个页面会打开?Laravel欢迎页面这很奇怪,你在public dir下的index.php文件中做了任何更改吗?以前我使用Apache,但我的pm决定使用nginxwow
php artisan serve
。。这就是工作,怎么做。。您应该为您的路由添加路由前缀nginx vhost
和route prefix
执行此任务,而不是添加路由前缀。。。谢谢,伙计