Laravel 5.3,使用api.example.com到example.com/api
发布时间:2021-01-11 20:31:06 所属栏目:Nginx 来源:互联网
导读:如何将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,这样我就可以
比使用
我正在使用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官方文档 (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Nginx:将所有不存在的请求重定向到index.php
- nginx – 在同一台服务器上升级2个Ghost博客,1作为服务运行
- Nginx配置未针对浏览器更新
- asp.net-mvc-2 – 关于nginx/mono 2.8的ASP.Net MVC 2
- cache – 如何使用nginx作为缓存反向代理来替换squid/varni
- 带有Nginx 1.6.2的CentOS 6.6-突然无法重新启动Nginx-Nginx
- ruby-on-rails – 错误乘客没有看到环境变量?
- 如何告诉nginx仅为一个域提供SSL?
- Nginx中的HSTS:是否应该在子域服务器块中添加Strict-Trans
- 从PHP触发Node.js事件
