I need to test sub-domains on my localhost. How can I effectively have this result of adding *.localhost.com
to my /etc/hosts/
file?
If it's not possible, how do I work around this problem? I need to test wildcard sub-domains on my localserver. It is a Django devserver, can the Django dev server handle the sub-domains? Can some other piece of software/routing give me the end result I want?
Install dnsmasq (I do this on all my Linux desktops as a DNS cache anyways). In
dnsmasq.conf
add the line:It is not possible to specify wildcards in the
/etc/hosts
file. Either specify the required hostnames explicitly or alternatively set up a local name server with the appropriate rules.I have written a dns proxy in Python. It will read wildcard entries in /etc/hosts. See here: https://github.com/hubdotcom/marlon-tools/blob/master/tools/dnsproxy/dnsproxy.py
You need to set up a DNS server and have each client use it for resolution. The server itself can be something as "light" as dnsmasq or as heavy as BIND.
Simple Workflow (no need to install anything)
I personally like to create a PAC file for that and make my browser just use it.
Step 1: create a file e.g.:
*.proxy.pac*
somewhere (I use my$home
folder)Step 2: paste this code (example is with port 8000):
Step 3: Make your Browser use this PAC file.
Youtube Video for PAC & Firefox
Step 4: Now you can test your app by accessing:
http://mysubdomain.localhost/
Step 5: Enjoy :)
I've tidied up an old project of mine:
https://github.com/airtonix/avahi-aliases
requirements:
Advantages over using dnsmasq or the python dns proxy:
You cannot use a wildcard in
/etc/hosts
.Have a look here for a good walkthrough on how to accomplish on OS X using BIND, the built-in but inactive DNS server, and Apache.
This DNS based solution worked perfectly in my case, without need to install anything : https://gist.github.com/fedir/04e60d679d5657d1f9f9aa10b3168282 (Mac OSX 10.9)
If you want to use
dnsmasq
withNetworkManager
you can (or even must?) startdnsmasq
fromNetworkManager
by addingto
/etc/NetworkManager/NetworkManager.conf
. Then the dnsmasq config goes to/etc/NetworkManager/dnsmasq.conf
or/etc/NetworkManager/dnsmasq.d/
resp.Copying from this blog here is how to do it on mac:
https://hedichaibi.com/how-to-setup-wildcard-dev-domains-with-dnsmasq-on-a-mac/