laravel - 为 laravel 安装了 Valet,但为什么 dnsmasq 不能正确解析?

标签 laravel homebrew dnsmasq laravel-valet php-7.3

我已经在我的 Mac( Mojave )上使用 Homebrew 软件为 laravel 安装了代客泊车服务。根据laravel's documentation我现在应该可以 ping *.test,但是当我不断收到以下错误时:

ping:cannot resolve foobar.test: Unknown host



看起来像是 dnsmasq 的问题。我已遵循所有建议 here ,但似乎没有任何帮助。
# Content of '/Users/<username>/.config/valet/dnsmasq.conf'

address=/.test/127.0.0.1
listen-address=127.0.0.1

我可以看到 .test 的解析器似乎设置正常。以下是 scutil --dns 的输出
DNS configuration

resolver #1
  search domain[0] : default
  nameserver[0] : 192.168.1.1
  if_index : 6 (en0)
  flags    : Request A records
  reach    : 0x00020002 (Reachable,Directly Reachable Address)

resolver #2
  domain   : local
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300000

resolver #3
  domain   : 254.169.in-addr.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300200

resolver #4
  domain   : 8.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300400

resolver #5
  domain   : 9.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300600

resolver #6
  domain   : a.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300800

resolver #7
  domain   : b.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 301000

resolver #8
  domain   : test
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

DNS configuration (for scoped queries)

resolver #1
  search domain[0] : default
  nameserver[0] : 192.168.1.1
  if_index : 6 (en0)
  flags    : Scoped, Request A records
  reach    : 0x00020002 (Reachable,Directly Reachable Address)

我还可以看到 dnsmasq 似乎运行正常。这是 brew services list 的输出:
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
httpd   started root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
mysql   started root /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
nginx   started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php     started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@7.1 started root /Library/LaunchDaemons/homebrew.mxcl.php@7.1.plist
php@7.2 started root /Library/LaunchDaemons/homebrew.mxcl.php@7.2.plist

我尝试过的其他事情:
  • 在阻止请求的情况下禁用我的防火墙。
  • 使用以下命令重新启动 dnsmasq(多次):sudo brew services restart dnsmasq
  • 使用 valet install 重新安装代客泊车服务
  • 检查/etc/hosts
  • 中没有冲突的路径

    有人有其他建议吗?

    编辑: sudo brew services restart --verbose dnsmasq 的输出
    `Stopping `dnsmasq`... (might take a while)
    ==> Successfully stopped `dnsmasq` (label: homebrew.mxcl.dnsmasq)
    ==> Generated plist for dnsmasq:
       <?xml version="1.0" encoding="UTF-8"?>
       <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
       <plist version="1.0">
         <dict>
           <key>Label</key>
           <string>homebrew.mxcl.dnsmasq</string>
           <key>ProgramArguments</key>
           <array>
             <string>/usr/local/opt/dnsmasq/sbin/dnsmasq</string>
             <string>--keep-in-foreground</string>
             <string>-C</string>
             <string>/usr/local/etc/dnsmasq.conf</string>
           </array>
           <key>RunAtLoad</key>
           <true/>
           <key>KeepAlive</key>
           <true/>
         </dict>
       </plist>
    
    
    /bin/launchctl enable system/homebrew.mxcl.dnsmasq
    /bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    ==> Successfully started `dnsmasq` (label: homebrew.mxcl.dnsmasq)
    

    编辑2:

    我想我现在正在取得进展。我在 console.app 中检查了 dnsmasq 并看到了错误消息:
    failed to open pidfile /usr/local/var/run/dnsmasq/dnsmasq.pid: No such file or directory
    ...这导致我here .原来我错过了 dnsmasq cd /usr/local/var/run/ 中的文件夹所以我跑了sudo mkdir dnsmasq现在 ping 实际上返回以下响应:
    PING foobar.test (127.0.0.1): 56 data bytes
    Request timeout for icmp_seq 0
    Request timeout for icmp_seq 1
    Request timeout for icmp_seq 2
    Request timeout for icmp_seq 3
    Request timeout for icmp_seq 4
    Request timeout for icmp_seq 5
    Request timeout for icmp_seq 6
    Request timeout for icmp_seq 7
    ...
    

    我不确定这意味着什么,或者它现在是否有效。

    当我在浏览器中访问 foobar.test 时,我收到消息 This site can’t be reached即使我已经创建了一个具有该名称的项目并使用 valet link foobar 链接了它.

    编辑 3:

    通过关闭隐身模式(如 here 所述),我现在 ping 工作正常,但我仍然得到 This site can’t be reached当我在浏览器中导航到 foobar.test 时。

    运行 curl foobar.test --verbose 时出现以下错误
    * Rebuilt URL to: foobar.test/
    *   Trying 127.0.0.1...
    * TCP_NODELAY set
    * Connected to foobar.test (127.0.0.1) port 80 (#0)
    > GET / HTTP/1.1
    > Host: foobar.test
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    * Recv failure: Connection reset by peer
    * Closing connection 0
    curl: (56) Recv failure: Connection reset by peer
    

    编辑 4
    cat /usr/local/etc/dnsmasq.conf | grep -i interface 的输出:
    # 10.1.2.3 to 192.168.1.1 port 55 (there must be an interface with that
    # specified interfaces (and the loopback) give the name of the
    # interface (eg eth0) here.
    # Repeat the line for more than one interface.
    #interface=
    # Or you can specify which interface _not_ to listen on
    #except-interface=
    # If you want dnsmasq to provide only DNS service on an interface,
    #no-dhcp-interface=
    # even when it is listening on only some interfaces. It then discards
    # working even when interfaces come and go and change address. If you
    # want dnsmasq to really bind only the interfaces it is listening on,
    #bind-interfaces
    # that these two Ethernet interfaces will never be in use at the same
    # Always give the InfiniBand interface with hardware address
    

    最佳答案

    请确认您有 /etc/resolver/test包含此行的文件:nameserver 127.0.0.1
    另外,编辑您的 /usr/local/etc/dnsmasq.conf通过取消注释并更改此行来取消文件:

    #interface=
    

    对此:
    interface=lo0
    

    然后再次使用 sudo brew services restart dnsmasq 重新启动服务然后再试一次。

    这个想法是在安装过程中 dnsmasq守护进程可能已绑定(bind)到某个不再可用的接口(interface)。
    通过将其更改为 lo0您会强制它只为始终存在的环回接口(interface)提供服务。我猜你不需要它在任何面向外部的接口(interface)上运行,因为我猜这都是为了开发目的。然而,如果你这样做,你可以添加更多这样的界面行:
    interface=lo0
    interface=en0
    

    关于laravel - 为 laravel 安装了 Valet,但为什么 dnsmasq 不能正确解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56165635/

    相关文章:

    php - Laravel 5.1 如何使用 lists() 方法对集合进行排序

    php - 流明/Laravel : Can't figure out how unittesting a json response works

    node.js - 在 MacOS 中使用 Homebrew 安装 Node 时卡住:fork.rb:49:in `write' : 管道损坏 (Errno::EPIPE)

    nginx - 从 macOS Sierra 升级 macOS High Sierra 后,Valet 停止工作

    PHP、JOIN 和 Laravel - 如何在连接表时分隔数组

    linux - Ubuntu 上的 Laravel 5.5 内部服务器错误

    postgresql - 如何指定Postgresql客户端版本以防止服务器版本不匹配?

    mono - 如何将 Homebrew 版本的 Mono 与 Xamarin 结合使用

    networking - 无法在 ubuntu 18.04 上运行多个 dnsmasq dhcp 服务器

    php - cURL + Laravel Valet + dnsmasq 不工作