验证方案,将 Laravel-admin 站点部署到 Apache 二级目录下

环境资源

环境:阿里云服务器 CenterOS 7.5 ,宝塔面板 Apache + php7.2.31

概况

问题:单端口号,部署多个项目(小项目很多,不想用多个端口号)
主要目的:验证一下,在二级目录的下部署站点的可能性。记录一下过程以及后续存在的问题。
目标结果:

域名 端口号 根目录 二级目录 访问地址
test.pj 88 /www/wwwroot/tests pj1,pj2 test.pj:88/t1, test.pj:88/t2

过程描述:

1. 在宝塔面板中添加一个站点(RootTest),确定好根目录。
2.进入 RootTest -> 设置 -> 配置文件,配置虚拟目录
    #PATH
    <Directory "/www/wwwroot/tests">
       Options FollowSymLinks
       Order deny,allow
       Deny from all
    </Directory>

    <Location / >
      Require all denied
    </Location>
    <Location /t1 >
      Require all granted
    </Location>
    <Location /t2 >
      Require all granted
    </Location>

    Alias /t1 "/www/wwwroot/tests/pj1/public"
    <Directory "/www/wwwroot/tests/pj1/public">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        Allow from all
        AllowOverride All
        Require all granted
        DirectoryIndex index.php index.html index.htm default.php default.html default.htm
    </Directory>

    Alias /t2 "/www/wwwroot/tests/pj2/public"
    <Directory "/www/wwwroot/tests/pj2/public">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        Allow from all
        AllowOverride All
        Require all granted
        DirectoryIndex index.php index.html index.htm default.php default.html default.htm
    </Directory>
3. 项目中的调整,暂时发现这些要调整的
    // 都以 t1 来举例
    // public/.htaccess 中增加
    RewriteBase /t1/

    // AppServiceProvider.php@boot() 中增加
    app('url')->forceRootUrl(config('app.url'));

    // 调用 admin_base_url() 的地方,外层要包裹一层 url()
    url(admin_base_url(xxx))

   // laravel-admin 的后台,如果使用了多后台扩展,session 要关注一下;
   // config('admin.route.middleware') 里面 
   'multi-session:path,/t1/admin'
4. 没关注到的点,还请多多提醒~

验证结果

正常页面都顺利跑起来了。
可能会存在一些问题还没发现,有没关注到的点,还请多多提醒。
最后吧,多个小站点需要挤一挤的,大概可以用一用这个方法吧。
如果资源够的话,还是不要这样搞了,难免会遇到坑要爬~

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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