>  기사  >  백엔드 개발  >  PHP:使用Apache如何在本地搭建泛解析呢?

PHP:使用Apache如何在本地搭建泛解析呢?

WBOY
WBOY원래의
2016-06-06 20:46:111165검색

目前我通过修改httpd-vhosts.confhosts文件,想要达到泛解析的目的。
但是在hosts文件中需要将要解析的域名事先写好。感觉这样子很麻烦,不知道有没有更好的实现方法呢?
httpd-vhosts.conf

<code><virtualhost>
    DocumentRoot "d:/www/"
    ServerName test.com
    ServerAlias *.test.com
</virtualhost>
</code>

hosts文件

<code>127.0.0.1       1.test.com
127.0.0.1       2.test.com
127.0.0.1       3.test.com
127.0.0.1       4.test.com
127.0.0.1       5.test.com
127.0.0.1       6.test.com
127.0.0.1       7.test.com
127.0.0.1       8.test.com
127.0.0.1       9.test.com
127.0.0.1       10.test.com
127.0.0.1       11.test.com
127.0.0.1       12.test.com
127.0.0.1       13.test.com
127.0.0.1       14.test.com
127.0.0.1       15.test.com
127.0.0.1       16.test.com
127.0.0.1       17.test.com
127.0.0.1       18.test.com
127.0.0.1       19.test.com
127.0.0.1       20.test.com
127.0.0.1       21.test.com
127.0.0.1       22.test.com
127.0.0.1       23.test.com
127.0.0.1       24.test.com
127.0.0.1       25.test.com
127.0.0.1       26.test.com
127.0.0.1       27.test.com
127.0.0.1       28.test.com
127.0.0.1       29.test.com
127.0.0.1       30.test.com
</code>

回复内容:

目前我通过修改httpd-vhosts.confhosts文件,想要达到泛解析的目的。
但是在hosts文件中需要将要解析的域名事先写好。感觉这样子很麻烦,不知道有没有更好的实现方法呢?
httpd-vhosts.conf

<code><virtualhost>
    DocumentRoot "d:/www/"
    ServerName test.com
    ServerAlias *.test.com
</virtualhost>
</code>

hosts文件

<code>127.0.0.1       1.test.com
127.0.0.1       2.test.com
127.0.0.1       3.test.com
127.0.0.1       4.test.com
127.0.0.1       5.test.com
127.0.0.1       6.test.com
127.0.0.1       7.test.com
127.0.0.1       8.test.com
127.0.0.1       9.test.com
127.0.0.1       10.test.com
127.0.0.1       11.test.com
127.0.0.1       12.test.com
127.0.0.1       13.test.com
127.0.0.1       14.test.com
127.0.0.1       15.test.com
127.0.0.1       16.test.com
127.0.0.1       17.test.com
127.0.0.1       18.test.com
127.0.0.1       19.test.com
127.0.0.1       20.test.com
127.0.0.1       21.test.com
127.0.0.1       22.test.com
127.0.0.1       23.test.com
127.0.0.1       24.test.com
127.0.0.1       25.test.com
127.0.0.1       26.test.com
127.0.0.1       27.test.com
127.0.0.1       28.test.com
127.0.0.1       29.test.com
127.0.0.1       30.test.com
</code>

你可以使用 dnsmasq 这个 DNS 缓存服务,它支持自定义泛解析,如:

<code>address=/test.com/127.0.0.1
</code>

在Hosts中直接绑定
127.0.0.1 *.test.com

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.