Setup wildcard subdomain in Laravel Homestead
Before start, you need to setup vagrant and ssh into the virtual machine
1 | $ vagrant up |
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 | local=/laravel.app/ |
Restart dnsmasq
1 | sudo /etc/init.d/dnsmasq restart |
3. Go back to host machine (I’m using OS X here)
Open up the Network Preferences
Click on the Advanced… tab
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 | $ dig subdomain.laravel.app @192.168.10.10 |
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: