【问题标题】:Homestead with subdomains带有子域的宅基地
【发布时间】:2017-09-20 15:14:23
【问题描述】:

我使用 homestead 和 Laravel 5.4,我需要启用子域,在我的主 windows 10 机器上,我在 (C:\WINDOWS\system32\drivers\etc\hosts) 记录中添加了一个主机:

192.168.10.10   myapp.dev
192.168.10.10   website.myapp.dev

所以这可以正常工作,当我导航到 website.myapp.dev 时,它会显示主页,就像我转到 myapp.dev 一样,而且我的宅基地服务器是 apache2 而不是 nginx

在这条路线上,当我转到 website.myapp.dev 时,我会在日志中得到预期的输出(website.myapp.dev):

Route::get('/',   function(Illuminate\Http\Request $request){
    \Log::info($request->fullUrl()); // logs website.bikser.dev

});

但是当我转到 website.myapp.dev 时,我的这条路线没有启动:

Route::domain('{account}.myapp.dev')->group(function () {

    Route::get('/{account}',    'WebsiteController@view');
});

所以我需要这条路线才能工作,所以我可以使用子域,我没有更改 .htaccess 文件中的任何内容,因为我不知道是否应该这样做,而且我尝试编辑 apache2.conf 并添加这些行:

<VirtualHost *:80>

ServerName myapp.dev

ServerAlias *.myapp.dev

</VirtualHost>

但我的{account}.myapp.dev 路由仍然没有启动,请帮助

编辑:

刚刚按照 @headmax 的建议添加了这段代码,但是当我导航到 myapp.dev 时,它说

NotFoundHttpException,这是我添加的代码:

 <VirtualHost *:80> 
ServerName myapp.dev 
DocumentRoot home/vagrant/code/public 
<Directory "home/vagrant/code/public/">  
  Options +Indexes +Includes +FollowSymLinks +MultiViews
  AllowOverride All 
  #Require local  
  Require all granted 
</Directory>
</VirtualHost>

【问题讨论】:

    标签: apache laravel laravel-5 laravel-5.4 homestead


    【解决方案1】:

    首先更改新文档根的右侧:

    sudo chown -R $USER:$USER home/vagrant/code/public
    

    注意:Debian 8 中的默认 Apache 配置要求每个 虚拟主机文件以 .conf 结尾。

    我们复制 默认虚拟主机 用于您自己的 site.conf 000-default.conf

    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myapp.dev.conf
    

    您需要编辑文件并在此处添加您的虚拟主机粘贴

    sudo nano /etc/apache2/sites-available/myapp.dev.conf
    

    我们需要这样的简单方式:

    <VirtualHost *:80>
        ServerAdmin admin@myapp.dev
        ServerName myapp.dev
        ServerAlias www.myapp.dev
        DocumentRoot /home/vagrant/code/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    现在我们已经创建了虚拟主机文件,我们可以启用了。

    sudo a2ensite myapp.dev.conf
    

    输出:启用站点 myapp.dev。要激活新配置, 你需要运行:service apache2 reload

    重启 Apache

    service apache2 reload //to reload configuration
    sudo systemctl restart apache2 //to apply the configuration change
    

    现在您已经完成了对站点的测试。

    你需要一个根目录来告诉apache你的站点文件存储在哪里。 这里的示例 myapp.dev 是一个文件夹,而 public 文件夹 是存储公共文件的(子)。

    <VirtualHost *:80> 
    ServerName myapp.dev 
    DocumentRoot home/vagrant/code/public 
    <Directory "home/vagrant/code/public/">  
      Options +Indexes +Includes +FollowSymLinks +MultiViews
      AllowOverride All 
      #Require local  
      Require all granted 
    </Directory>
    </VirtualHost>
    

    【讨论】:

    • @Mikail Mika 我编辑并适应了你的上下文,我只是添加了和标签 错过了,
    • 谢谢你,但它仍然不起作用,当我到达 website.myapp.devmyapp.dev 它抛出 NotFoundHttpException 但是其他路线,如 myapp.dev/something 工作,你使用上面宅基地代码?
    • 你把这个虚拟放在好文件上了吗?如果您使用的是 linux,则需要在此步骤之前添加具有良好权限和设置的新 doc root。在我的第一篇文章中添加该过程。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2023-03-16
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2020-12-14
    • 2015-08-04
    相关资源
    最近更新 更多