Localhost 使用 DNSMasq 设置和自定义 Vhost 导致 404

Localhost Leads to 404 with DNSMasq Setup and custom Vhost

我已将 DNSMasq 配置为使用原生 Apache2、原生 PHP5 和自制软件 MySQL 以及 DNSMasq 为 OSX Yosemite 本地测试服务器工作。现在一切正常,但使用当前的 DNS 设置,我只能在主机配置中使用 127.0.0.1 访问 PHPMyAdmin,每个 WordPress 设置也是如此。主机必须是 127.0.0.1 Localhost 不再工作以访问我的本地主机。

这里是我的一些配置:

/etc/hosts :

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 

解析器 /etc/resolver/dev :

nameserver 127.0.0.1

/usr/local/etc/dnsmasq.conf中我添加了:

listen-address=127.0.0.1
address=/dev/127.0.0.1

现在当我加载 localhost 或 http://localhost 我得到一个 404:

::1 - - [22/Feb/2015:08:12:33 +0300] "GET / HTTP/1.1" 404 198

Ping 正常:

ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.106 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.116 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.113 ms
^C
--- localhost ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.050/0.096/0.116/0.027 ms

我的 VirtualHost 在 /private/etc/apache2/extra/httpd-vhosts.conf

<Virtualhost *:80>
VirtualDocumentRoot "/Users/me/webdesign/%1"
ServerName vhosts.dev
ServerAlias *.dev
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
ErrorLog "/Users/me/webdesign/vhosts-error_log"
<Directory "/Users/me/webdesign/*">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</Virtualhost>

在这个 /etc/apache2/httpd.conf 中,我添加到最后以停止启动 Apache 时的错误并使 PHPMYAdmin 在本地主机上工作。

ServerName localhost
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    <IfModule mod_authz_core.c>
      Require all granted
    </IfModule>
    <IfModule !mod_authz_core.c>
      Order allow,deny
      Allow from all
    </IfModule>
</Directory>

当我 运行 scutil 我看到

scutil --dns
DNS configuration

resolver #1
  search domain[0] : Home
  nameserver[0] : 192.168.1.1
  if_index : 4 (en1)
  flags    : Request A records
  reach    : Reachable,Directly Reachable Address

resolver #2
  domain   : dev
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : Reachable,Local Address

DNS configuration (for scoped queries)

resolver #1
  search domain[0] : Home
  nameserver[0] : 192.168.1.1
  if_index : 4 (en1)
  flags    : Scoped, Request A records
  reach    : Reachable,Directly Reachable Address

有什么办法可以让 localhost 再次工作吗?

阅读 here 当您添加一个新的 DocumentRoot 时,您会丢失 localhost 使用的旧文件。所以我添加了

<VirtualHost *:80> 
ServerName localhost 
DocumentRoot /Library/WebServer/Documents/ 
</VirtualHost>

给它指明方向。现在 localhost 再次工作。对于在 .dev 下服务的站点,仍然需要 127.0.0.1。