使用dingo配置完路由,但是访问总是404错误

1. 运行环境

1). 当前使用的 Laravel 版本?

5.5

2). 当前使用的 php/php-fpm 版本?

PHP 版本:

7.4
php-fpm 版本:

7.4

3). 当前系统

centos7

4). 业务环境

生产环境

5). 相关软件版本

2. 问题描述?

使用ip:port访问默认index.php是正常的,但是访问ip:port/api/home就报404的nginx错误

在.env文件中dingo配置如下
API_STANDARDS_TREE=vnd #环境
API_SUBTYPE=myapp #子类型
API_PREFIX=api #前缀
API_VERSION=v1 #版本
API_NAME=MyAPI #名字(使用API Blueprint命令才会用到)
API_CONDITIONAL_REQUEST=false #带条件的请求
API_STRICT=false #Strict模式
API_DEFAULT_FORMAT=json #响应格式
API_DEBUG=true #调试模式

在routes/api.php文件如下

//接管路由
$api = app(‘Dingo\Api\Routing\Router’);

$api->version(‘v1’, function ($api) {
//需要权限验证
$api->group([
‘namespace’ => ‘App\Api\Controllers’,
‘middleware’ => ‘jwt.auth’,
], function ($api) {
//首页
// $api->get(‘home’, ‘HomeController@index’);
//问题数
$api->get(‘theme/questionNum’, ‘HomeController@questionNum’);
//问题
$api->post(‘question/show’, ‘HomeController@questionShow’);
//答案
$api->get(‘question/answer’, ‘HomeController@answer’);
$api->any(‘pay/wxpay’, ‘PayController@wxpay’);
//提交订单
$api->post(‘user/addOrder’, ‘OrderController@addOrder’);
$api->get(‘orderList’, ‘OrderController@index’);
$api->post(‘orderInfo’, ‘OrderController@orderInfo’);
$api->post(‘endtheme’, ‘OrderController@endtheme’);

});
//不需要权限验证
$api->group([
    'namespace' => 'App\Api\Controllers',
], function ($api) {
    $api->post('wxShare', 'PayController@wxShare');
    $api->post('shareInfo', 'OrderController@shareInfo');
    //登录
    // $api->post('user/login', 'userController@authenticate');
    $api->post('user/login', 'UserController@login')->name('login');
    //注册
    $api->post('user/register', 'UserController@register')->name('register');

    $api->get('bannerList', 'HomeController@bannerList');
    $api->get('home', 'HomeController@index');

    //话题分类列表
    $api->get('theme/show', 'HomeController@show');


    //上传图片
    $api->post('upload/images', 'UploadController@uploadImages');
    //上传视频
    $api->post('upload/video', 'UploadController@uploadVideo');

    //发送短信
    $api->post('sendSms', 'UserController@sendSms');
    //找回密码/重置密码
    $api->post('user/resetPwd', 'UserController@resetPassword');



    $api->get('auth/social', 'UserController@socialStore');
    $api->any('oauth_callback', 'UserController@oauth_callback');

    $api->any('pay/wxnotify', 'PayController@wxnotify');
    $api->any('weixin/valid', 'WeixinController@valid');

    $api->get('groupBooking/list', 'GroupBookingController@index');

});

});

3. 您期望得到的结果?

期望访问/api/home能够路由到指定php页面

4. 您实际得到的结果?

访问ip:port/api/home就报404的nginx错误

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 2

nginx的404错误那就是还没到框架路由,可能是伪静态问题,如果是框架404那才是路由问题~

1年前 评论

果然是伪静态问题,赞

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!