About a month ago, Freek Van der Herten wrote some Laravel Homestead tips on his blog. The item that stood out for me was avoiding having to edit the hosts file. I won't go into much more detail here, but essentially this uses a utility called dnsmasq to tell your computer to resolve configured domains locally.

Have a read over Freek's article and get dnsmasq up and running and we'll continue.

Wildcard hosts

Now that you've setup dnsmasq, you can resolve *.dev to your Homestead machine easily, but you still need that manual step of either configuring a new domain in your Homestead.yaml file or using the serve command within the virtual machine itself.

Whilst neither of these methods take a particularly long time to complete, it's still a few seconds of repetition that can be avoided with some tweaking of your default nginx configuration using wildcard hosts.

What we'll be doing, is telling nginx to listen for anything sent to it that isn't explicitly configured and look for the domain name in your (default) /home/vagrant/Code directory.

Configuring nginx

Create a new file called /etc/nginx/sites-available/dev_domains and add the following:

server {
    listen 80 default_server;
    # Only if you want SSL 
    # listen 443 ssl;
    server_name _;
    root /home/vagrant/Code/$host/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/dev_domains-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {