将 Laravel Nova 移至子域

Posted

技术标签:

【中文标题】将 Laravel Nova 移至子域【英文标题】:Move Laravel Nova to subdomain 【发布时间】:2021-01-12 05:28:33 【问题描述】:

我想将 Laravel Nova 移动到 nova.mydomain.com 而不是 mydomain.de/nova。我已经搜索了 GitHub 和 ***,但是,这些解决方案对我不起作用。目前我正在尝试this one。

它也有效。 Nova 现在可通过nova.mydomain.de 获得。然而,现在我面临着另外三个问题。

    当我尝试访问 mydomain.de 上的主域时,我还看到了 Laravel Nova 仪表板。它甚至没有重定向我,它只是向我展示了主域上的 Laravel Nova 仪表板!

    当我在 Laravel Nova 仪表板上单击我的资源上的链接时,它会自动将 nova. 附加到所有链接...

    nova. 下也可以找到完整的站点,包括来自主域的所有路由。例如mydomain.com/post/myFirstPost 也可以在nova.mydomain.com/post/myFirstPost 下使用

我在 Mac 上运行 Laravel ValetLaravel 8。我在我的Sites 文件夹中创建了一个nova 目录,其中还包含mydomain 项目。 nova 文件夹只是一个指向 mydomain 项目的符号链接。

我该如何解决我的问题...不幸的是,网上没有很多讨论和解决方案。

我的 nova.php 配置文件。

<?php

use Laravel\Nova\Actions\ActionResource;
use Laravel\Nova\Http\Middleware\Authenticate;
use Laravel\Nova\Http\Middleware\Authorize;
use Laravel\Nova\Http\Middleware\BootTools;
use Laravel\Nova\Http\Middleware\DispatchServingNovaEvent;

return [

    /*
    |--------------------------------------------------------------------------
    | Nova App Name
    |--------------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to display the name of the application within the UI
    | or in other locations. Of course, you're free to change the value.
    |
    */

    'name' => env('NOVA_APP_NAME', env('APP_NAME')),

    /*
    |--------------------------------------------------------------------------
    | Nova App URL
    |--------------------------------------------------------------------------
    |
    | This URL is where users will be directed when clicking the application
    | name in the Nova navigation bar. You are free to change this URL to
    | any location you wish depending on the needs of your application.
    |
    */

    'url' => 'nova.' . env('APP_DOMAIN'),

    /*
    |--------------------------------------------------------------------------
    | Nova Path
    |--------------------------------------------------------------------------
    |
    | This is the URI path where Nova will be accessible from. Feel free to
    | change this path to anything you like. Note that this URI will not
    | affect Nova's internal API routes which aren't exposed to users.
    |
    */

    'path' => '/',

    /*
    |--------------------------------------------------------------------------
    | Nova Authentication Guard
    |--------------------------------------------------------------------------
    |
    | This configuration option defines the authentication guard that will
    | be used to protect your Nova routes. This option should match one
    | of the authentication guards defined in the "auth" config file.
    |
    */

    'guard' => env('NOVA_GUARD', null),

    /*
    |--------------------------------------------------------------------------
    | Nova Password Reset Broker
    |--------------------------------------------------------------------------
    |
    | This configuration option defines the password broker that will be
    | used when passwords are reset. This option should mirror one of
    | the password reset options defined in the "auth" config file.
    |
    */

    'passwords' => env('NOVA_PASSWORDS', null),

    /*
    |--------------------------------------------------------------------------
    | Nova Route Middleware
    |--------------------------------------------------------------------------
    |
    | These middleware will be assigned to every Nova route, giving you the
    | chance to add your own middleware to this stack or override any of
    | the existing middleware. Or, you can just stick with this stack.
    |
    */

    'middleware' => [
        'web',
        Authenticate::class,
        DispatchServingNovaEvent::class,
        BootTools::class,
        Authorize::class,
        \Vyuldashev\NovaPermission\ForgetCachedPermissions::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Nova Pagination Type
    |--------------------------------------------------------------------------
    |
    | This option defines the visual style used in Nova's resource pagination.
    | You may choose between 3 types: "simple", "load-more" and "links".
    | Feel free to set this option to the visual style you like.
    |
    */

    'pagination' => 'simple',

    /*
    |--------------------------------------------------------------------------
    | Nova Action Resource Class
    |--------------------------------------------------------------------------
    |
    | This configuration option allows you to specify a custom resource class
    | to use instead of the one that ships with Nova. You may use this to
    | define any extra form fields or other custom behavior you need.
    |
    */

    'actions' => [
        'resource' => ActionResource::class,
    ],

];

亲切的问候

【问题讨论】:

【参考方案1】:

将您的子域根目录设置为主域根目录。这通常必须在您的网络服务器(如 apache、nginx)中完成

config/nova.php 中的domain 设置为您的子域。

别忘了php artisan optimize:clear

【讨论】:

以上是关于将 Laravel Nova 移至子域的主要内容,如果未能解决你的问题,请参考以下文章

如何将 Vuex 添加到我的 Laravel Nova 工具中?

尝试通过 Composer 将 Laravel/Nova 更新到最新版本时出现 INVALID CREDENTIALS 错误

text CMD将Laravel移至LocalHost

cname vhosts 将 cname 设置为动态子域 laravel

Laravel Nova:按列分组表单字段

如何在 laravel 中创建子域