Homestead 有子域

Homestead with subdomains

我使用 homestead 和 Laravel 5.4 并且我需要启用 sub-domains,在我的主 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,而且我的 homestead 服务器是 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');
});

所以我需要这条路线才能工作,所以我可以使用 sub-domains ,我没有更改 .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>

首先更改您的新文档根目录的权限:

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

Note: The default Apache configuration in Debian 8 requires that each virtual host file end in .conf.

我们复制默认虚拟主机给你自己site.conf000-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

Output: Enabling site myapp.dev. To activate the new configuration, you need to run: service apache2 reload

重新启动 Apache

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

现在您已完成站点测试。

您需要一个 根目录 来告诉 apache 您的站点文件存储在哪里。 这里的例子 myapp.dev 是一个文件夹 public 文件夹 是 (a child) 其中 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>