简体   繁体   English

Laravel 通配符子域路由

[英]Laravel Wildcard Subdomain routing

I have some problems with wildcard subdomain routing with Laravel. Laravel 的通配符子域路由存在一些问题。 I want to create subdomain for every user.我想为每个用户创建子域。 So I'm doing like this:所以我这样做:

My API.js in Laravel routes:我在 Laravel 路线中的 API.js :

    Route::domain('{user}.mydomain.com')->group(function () {
        Route::get('user', [UserController::class, 'getUserDetails'])->name('user'); 
    });

And this is my vhosts这是我的虚拟主机

<VirtualHost *:80>
    ServerAdmin domain@gmail.com
    DocumentRoot "C:\xampp\htdocs\Project\public"
    DirectoryIndex index.php
    ServerName mydomain.com
    ServerAlias *.mydomain.com

    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

And C:\Windows\System32\drivers\etc\hosts和 C:\Windows\System32\drivers\etc\hosts

127.0.0.2 mydomain.com
127.0.0.2 *.mydomain.com

What am I doing wrong?我究竟做错了什么?

EDIT: I'm using Windows编辑:我正在使用 Windows

Windows does not support wildcard entries in the hosts file. Windows 不支持 hosts 文件中的通配符条目。 You'll need to specify alle the individual subdomains.您需要指定所有单独的子域。

You simply need a DNS service.您只需要一个 DNS 服务。 i use Acrylic DNS Proxy on Windows and they have a nice documentation how to setup in windows environment.我在 Windows 上使用Acrylic DNS 代理,他们有一个很好的文档如何在 windows 环境中设置。

Link for Acrylic Documentation亚克力文档链接

Simply follow the documentation and add your hosts in Acrylic UI host configuration at the bottom as listed here只需按照文档并在此处列出的底部的 Acrylic UI 主机配置中添加您的主机

127.0.0.1 *.mydomain.com domain.com

Don't forget to restart Acrylic DNS Proxy service after setting up, should work like a charm.设置后不要忘记重新启动 Acrylic DNS 代理服务,应该会像魅力一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM