首页 Nginx Laravel 5.3,使用api.example.com到example.com/api

Laravel 5.3,使用api.example.com到example.com/api

如何将api.example.com路由到example.com/api,这样我就可以api.example.com/v1/users 比使用example.com/api/v1/users. 我正在使用Nginx,谢谢.最佳答案确保这两个步骤就位.检查您的nginx配置/etc/nginx/conf.d/example.conf并将域包含在server_

如何将api.example.com路由到example.com/api,这样我就可以

api.example.com/v1/users 

比使用

example.com/api/v1/users.

我正在使用Nginx,谢谢.
最佳答案
确保这两个步骤就位.

检查您的nginx配置/etc/nginx/conf.d/example.conf并将域包含在server_name中,如下所示:

server_name example.com api.example.com;

检查routes / api.php文件中是否有路由设置.使用子域组是可选的,但请确保您具有正确的路由.

使用域组的示例:

Route::group(['domain' => 'api.example.com'],function () {
    Route::get('/v1/users',['as' => 'api.users.index','uses' => 'UserController@index']);
}

不使用域组并允许两个URL都指向同一Controller的示例(请务必按照“ as”定义其自己的路由名称).

Route::get('/v1/users','uses' => 'UserController@index']);
Route::get('/api/v1/users',['as' => 'users.index','uses' => 'UserController@index']);

更新:

有关使用子域路由https://laravel.com/docs/5.3/routing#route-group-sub-domain-routing的信息,请参考Laravel 5.3官方文档

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/yunying/nginx/20210111/15339.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部