7

I'm not even 100% sure how to ask this question. The answer might be out there, but I can't find it.

So I've set up virtual hosts for my Mac and I do all my development locally on my computer. I have a vhost folder in my Sites folder, and I have a list of folders, such as:

recipes.cam
database.cam
sandbox.cam
codeigniter.cam

and in my /etc/hosts file I have an entry for each one:

# vhosts
127.0.0.1 recipes.cam
127.0.0.1 database.cam
127.0.0.1 sandbox.cam
127.0.0.1 codeigniter.cam
# ...    

And this works great. When I go to http://recipes.cam in my browser, it shows the contents of the ~/Sites/vhosts/recipes.cam.

So this is my question: Is there a way to have any address that end in .cam to redirect to localhost? So I don't have to create a new entry in hosts every time I add a new directory (it happens pretty often).

I tried 127.0.0.1 *.cam in my hosts file, but it didn't work :-/

CWSpear
  • 3,230
  • 1
  • 28
  • 34
  • You could set up your own DNS server that responds to anything under the .cam domain. However, setting up such a server is off topic for Stack Overflow but might be appropriate on [Server Fault](http://serverfault.com). – Greg Hewgill May 04 '12 at 06:51
  • Ok, maybe I'll move my post to there. I'm a PHP/jQuery Developer and use this site often, so it's where I figured I'd start. Thanks. – CWSpear May 04 '12 at 06:52
  • This is something better implemented as a proxy server OR local dns server. – Mahmoud Al-Qudsi May 04 '12 at 07:03

1 Answers1

7

The best solution I've been able to find is DNSMasq.

Justin Carmony's blog post helped me set it up. His original question was more about why .local was so slow after upgrading OSX or something like that, but the solution was the same: DNSMasq.

http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/

Now, basically all *.cam address go to my local IP. I have it set up so all I have to do is create a folder, list test.cam and I'm off and running with a full LAMP stack.

CWSpear
  • 3,230
  • 1
  • 28
  • 34
  • I wrote up an updated version for Yosemite, using dnsmasq and ngnix (for proxying to different ports), fwiw. Based on Justin & other's posts. http://blog.inkandfeet.com/How-To-Get-Dev-Addresses-On-Mac-Os-X-1010-Yosemite-In-5-Simple-Steps – skoczen Feb 20 '15 at 13:36