Before start, you need to setup vagrant and ssh into the virtual machine

1
2
$ vagrant up
$ vagrant ssh

1. Edit your Nginx config

1
$ sudo vim /etc/nginx/sites-available/laravel.app

In the server_name there

1
server_name laravel.app *.laravel.app;

2. Install dnsmasq & configure

1
$ sudo apt-get install dnsmasq

Then edit the config file

1
$ sudo vim /etc/dnsmasq.conf

Add in the following content

1
2
3
4
local=/laravel.app/
domain=laravel.app

address=/laravel.app/127.0.0.1

Restart dnsmasq

1
$ sudo /etc/init.d/dnsmasq restart

3. Go back to host machine (I’m using OS X here)

open network preference

Open up the Network Preferences

Network preference - overview

Click on the Advanced… tab

Network preference - DNS settings

Now add these DNS to the settings, in the DNS tab

NOTE: for 192.168.1.1, this you should follow your router address, because some may be 192.168.0.1 or others

The /etc/hosts value would be

1
127.0.0.1      laravel.app

4. Verify

Before that, double check your /etc/hosts in the host OS

1
127.0.0.1      laravel.app

Now you try to dig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ dig subdomain.laravel.app @192.168.10.10

; <<>> DiG 9.8.3-P1 <<>> subdomain.laravel.app @192.168.10.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62725
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;subdomain.laravel.app. IN A

;; ANSWER SECTION:
subdomain.laravel.app. 0 IN A 127.0.0.1

;; Query time: 11 msec
;; SERVER: 192.168.10.10#53(192.168.10.10)
;; WHEN: Mon Nov 30 12:14:00 2015
;; MSG SIZE rcvd: 62

Now try in your browser, type in the address subdomain.laravel.app:8000

NOTE:

Sometime you may encounter a problem which it doesn’t work, so in this case you have to clear your DNS cache (for OSX, refer here)

References: