Setting up wildcard domains on local host (OS X 10.5)?
Asked Answered
M

3

9

I am starting to develop a site which basically acts as WordPress MU, in the sense that a user can signup and have their own blog. I will be coding this in Rails, however I am hoping to be able to utilize wildcard subdomains, so I can use the format such as blog.example.com. I've done some searching but I can't find any good resources.

Since I am using Rails, I'm not sure where to put this, as I am using Mongrel, and not Apache. I can bypass doing this on my local machine by developing remotely on my server, however I would only like to keep this as a last resort.

I can give more details about my development environment if needed, but here are the basics:

  • Mac OS X Leopard 10.5.6
  • Ruby 1.8.7
  • Rails 2.3.2
Mathison answered 26/3, 2009 at 4:50 Comment(6)
What's the part you're having trouble with?Manvel
I can't get it setup at all. The guides I have found that talk about it talk about the /etc/hosts file, which I can't find on my computer. It may be because I just reformatted and I don't have MAMP or anything setup. It's just Ruby/Rails. I just need help figuring out how to set it up to work.Mathison
On Mac OS X (if I remember correctly), you'll need to edit the hosts in netinfo...Manvel
... but this really isn't a programming question, then. Let's hope IT Stack Overflow comes soon.Manvel
Im curious as to why this should be removed? Obviously you have been a member here longer, but I have a question about my development environment that will let me program my site the way I want it. There are other ?'s like mine that weren't removed, the tags are setup, so why should mine be removed?Mathison
I'm confused about the /etc/hosts comment: on my 10.5 system: $ ls -l /etc/hosts -rw-r--r-- 1 root wheel 235 Jun 28 2008 /etc/hostsUnteach
C
14

Strictly speaking, it's not possible to do that in the hosts file (at least on OS X). It's possible to simulate the behavior with Firefox by configuring it to use a proxy autoconfigure script.

Create a file with the following javascript (I use ~/.proxy.pac)

function FindProxyForURL(url, host) {
  if (shExpMatch(host,"*.<YOUR_DOMAIN>")) {
    //alert("proxy local")
    return "PROXY localhost";
  }
//alert("proxy direct")
return "DIRECT";
}

Then in Firefox > Preferences > Advanced > Network > Settings... > Automatic Proxy Configuration URL:

file:///Users/USERNAME/.proxy.pac

Never tried it in Safari, but it supports PAC files also, so perhaps it works...

The only other alternative I know is to set up a full blown DNS server on your PC...

Concussion answered 26/3, 2009 at 9:1 Comment(2)
YES! Brilliant! I've been searching for a solution to this for ages!Balk
Works for Chrome as well, I think it's system wide as far as browsing is concerned on OSXHemi
S
3

I couldn't get Nick's code to work with the standard localhost:3000 setup running ruby on rails on a Max OSX 10.5.8. So, I changed the function to the following. This now allows me to go to http://localhost/ and http://foo.localhost/ (and also ignores the port)

function FindProxyForURL(url, host) {
  if (shExpMatch(host, "*localhost")) {
    return "PROXY localhost:3000";
  }
  return "DIRECT";
}

Interesting - www.localhost was not working so well - firefox wanted to redirect to www.localhost.com. Something to be aware of.

Symbolics answered 3/10, 2009 at 6:41 Comment(0)
C
2

I had this same problem, and it turns out it's pretty easy to get named running on OSX (it's already preinstalled!) Check out http://mikeferrier.ca/2011/04/04/setting-up-wildcard-dns-on-localhost-domains-on-osx/ for instructions.

Cardoso answered 26/4, 2011 at 18:59 Comment(1)
As an addition, to use this without an internet connection see this question at serverfault: serverfault.com/questions/22419/…Collyrium

© 2022 - 2024 — McMap. All rights reserved.