How to test sub-domains on my localhost on a mac?

Must be adding to the file /etc/hosts:

127.0.0.1       localhost blog.localhost lvh.me blog.lvh.me

Example for Vim editor (small overview about working in Vim)

  1. Run to edit file /etc/hosts:

     sudo vi /etc/hosts
    
  2. In Vim press on keyboard button i to switch on edit mode

  3. Add this line:

     127.0.0.1       localhost blog.localhost lvh.me blog.lvh.me
    
  4. Save file:

  • Press button Esc and after press together buttons shift :

  • Now you will see line in which write x and press Enter

Thats all, localhost, blog.localhost, lvh.me and blog.lvh.me are already available for all ports that you are using.


Edit the file /etc/hosts, add the following line:

127.0.0.1 example.com blog.example.com

Then try http://example.com:8000/ and http://blog.example.com:8000/