apache 主机文件和多个子域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1078193/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:50:10  来源:igfitidea点击:

hosts file and multiple sub-domains

apachewindows-xpdnssubdomainlocalhost

提问by Arpit Tambi

For local testing (and learning), I wish to use x.com host name instead of localhost. I changed my Windows XP host file to this -

对于本地测试(和学习),我希望使用 x.com 主机名而不是 localhost。我将我的 Windows XP 主机文件更改为此 -

127.0.0.1       x.com

Now http://x.com/works beautifully but http://www.x.comdoesn't. :(

现在http://x.com/工作得很漂亮,但http://www.x.com没有。:(

What changes should I make so that www.x.com, sub1.x.com, sub2.x.com etc.. all work on local. WordpressMU will lets users create sub-domains dynamically.

我应该进行哪些更改,以便 www.x.com、sub1.x.com、sub2.x.com 等都在本地工作。WordpressMU 将允许用户动态创建子域。

I am basically trying to setup WordpressMU locally. I'm using Apache/2.2.4, PHP/5.2.4, and MySQL5.

我基本上是在尝试在本地设置 WordpressMU。我使用的是 Apache/2.2.4、PHP/5.2.4 和 MySQL5。

Please help!

请帮忙!

回答by Jesper

You can also put all the host names for an IP address on the same line:

您还可以将 IP 地址的所有主机名放在同一行:

127.0.0.1 x.com www.x.com sub1.x.com sub2.x.com

If you have a lot of sub-names, it would certainly be easier with a wildcard but unfortunately this is not supported with the hosts file.

如果您有很多子名称,使用通配符肯定会更容易,但不幸的是,hosts 文件不支持。

Alternatively you could download the trial version of Simple DNS Pluswhich you can use to run a local DNS server on your XP machine (make sure to setup TCP/IP to use 127.0.0.1 for DNS). This allows you to setup wildcard entries like *.x.com.

或者,您可以下载Simple DNS Plus的试用版,您可以使用它在 XP 机器上运行本地 DNS 服务器(确保设置 TCP/IP 以使用 127.0.0.1 作为 DNS)。这允许您设置通配符条目,例如 *.x.com。

回答by Oren Trutner

You can repeat the same IP address several times to redirect multiple host names. You have to list the full host names though -- you can't list domain names or wildcards and expect all hosts in that domain to redirect to the IP address.

您可以多次重复相同的 IP 地址以重定向多个主机名。但是,您必须列出完整的主机名——您不能列出域名或通配符并期望该域中的所有主机都重定向到 IP 地址。

127.0.0.1 x.com
127.0.0.1 www.x.com
127.0.0.1 sub1.x.com
127.0.0.1 sub2.x.com

回答by iloahz

You may try AngryHosts, with which you can add wildcard hosts rules.

您可以尝试AngryHosts,您可以使用它添加通配符主机规则。