macos 在 Mac OS X 上通过模式将地址重定向到本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10444055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redirect Addresses to localhost by Pattern on Mac OS X
提问by CWSpear
I'm not even 100% sure how to ask this question. The answer might be out there, but I can't find it.
我什至不能 100% 确定如何问这个问题。答案可能就在那里,但我找不到。
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:
所以我已经为我的 Mac 设置了虚拟主机,并且我在我的计算机上本地完成了我的所有开发。我的vhost
文件夹中有一个文件Sites
夹,我有一个文件夹列表,例如:
recipes.cam
database.cam
sandbox.cam
codeigniter.cam
and in my /etc/hosts
file I have an entry for each one:
在我的/etc/hosts
文件中,每个条目都有一个条目:
# 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.camin my browser, it shows the contents of the ~/Sites/vhosts/recipes.cam
.
这很好用。当我在浏览器中访问http://recipes.cam时,它会显示~/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).
所以这是我的问题:有没有办法让任何.cam
以重定向到本地主机的地址结束?所以我不必hosts
每次添加新目录时都创建一个新条目(这种情况经常发生)。
I tried 127.0.0.1 *.cam
in my hosts
file, but it didn't work :-/
我127.0.0.1 *.cam
在我的hosts
文件中尝试过,但没有用:-/
采纳答案by CWSpear
The best solution I've been able to find is DNSMasq.
我能找到的最好的解决方案是 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.
Justin Carmony 的博客文章帮助我进行了设置。他最初的问题更多是关于为什么.local
升级 OSX 或类似的东西后这么慢,但解决方案是一样的:DNSMasq。
http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/
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.
现在,基本上所有 *.cam 地址都转到我的本地 IP。我已经设置好了,所以我所要做的就是创建一个文件夹,列出 test.cam 并且我已经关闭并使用完整的 LAMP 堆栈运行。