Local Domain & Subdomain Testing in Mac & Linux
By Justin
What to do when you want to test a domain name locally? Such as www.yourawesomeproject.com or what about a subdomain (aka wildcard domain) like blog.yourawesomeproject.com or jmitchel3.yourawesomeproject.com? Here's a quick guide to do it:
-
Open up terminal
-
sudo nano /etc/hosts You should see something like:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
- Add each subdomain you want to use
127.0.0.1 localhost
127.0.0.1 www.yourawesomeproject.com
127.0.0.1 yourawesomeproject.com
127.0.0.1 blog.yourawesomeproject.com
- Run your project such as with Django:
python manage.py runserver
- Open your browser to:
http://www.yourawesomeproject.com:8000
or
http://blog.yourawesomeproject.com:8000
Notice that 8000 is the default port for running Django. You can change this port number as needed.
Enjoy!