Managing Wildcard Subdomains in Laravel Homestead on Ubuntu

4 March 2017

Updated at: 28 March 2019

Imagine the scenario where you have multiple subdomains, such as multiple locales for the internalization of your application served as en.example.test and es.example.test. You don't need to put each of them as a seperate entry to your both homestead config file and the hosts file if all of them will be served from the same application. There is of course an easier way.

Homestead Configuration

Let's assume our application is located within the ~/Code/Example folder and we want to map it to example.test, furthermore, the ip address assigned to our box is

$ nano ~/Homestead/Homestead.yaml

The most simple Homestead config will be like below.

ip: ""
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/

- ~/.ssh/id_rsa

- map: ~/Code/Example
to: /home/vagrant/Code/Example

- map: example.test
to: /home/vagrant/Code/Example/public

- homestead

Nginx Configuration

Then, ssh into your vagrant box and edit the nginx.conf of the example.test.

$ cd ~/Homestead && vagrant up && vagrant ssh
$ sudo nano /etc/nginx/sites-available/example.test

And just add the wildcard entry to the server_name.

server_name example.test *.example.test

And reload the nginx configuration.

$ sudo service nginx reload
$ exit

dnsmasq Entry

Then on your local machine, add a dnsmasq entry.

$ sudo nano /etc/NetworkManager/dnsmasq.d/local

Just add the entry below.


Finally, restart the network-manager.

$ sudo service network-manager restart

Now everything should be ok. You don't need to add individual entries for each of the subdomains of your application. For instance, both en.example.test and es.example.test will be served without adding a seperate configuration for each.