【问题标题】:Localhost Leads to 404 with DNSMasq Setup and custom Vhost本地主机通过 DNSMasq 设置和自定义 Vhost 导致 404
【发布时间】:2015-02-22 05:35:42
【问题描述】:

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

这是我的一些配置:

/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

我的虚拟主机在/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 在 localhost 上工作。

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 再次工作吗?

【问题讨论】:

    标签: apache dns osx-yosemite dnsmasq


    【解决方案1】:

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

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

    显示它的方式。现在 localhost 再次工作。不过,对于在 .dev 下提供服务的网站,仍然需要 127.0.0.1。

    【讨论】:

      猜你喜欢
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 2013-04-07
      • 2018-12-25
      相关资源
      最近更新 更多