macOS Sierra 上的 Apache 配置不当 - 虚拟主机无法工作

macOS Sierra 上的 Apache 配置不当 - 虚拟主机无法工作

我正在通过 Homebrew 安装整个 LAMP 堆栈(Apache、PHP、MySQL、Dnsmasq)。

以下是配置的简要摘要:

ServerName localhost

Listen 80

DocumentRoot "/Users/your_user/Sites"
<Directory "/Users/your_user/Sites">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

只要这些,一切都会好起来。

在下一部分中,当我尝试使用我知道过去曾经起作用的配置添加虚拟主机时,遇到了错误。

LoadModule vhost_alias_module libexec/mod_vhost_alias.so

<VirtualHost *:80>
    DocumentRoot /Users/elzi/Sites
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
  ServerName dev
  ServerAlias *.dev
  VirtualDocumentRoot /Users/elzi/Sites/%-2+
</VirtualHost>

现在我甚至不担心 PHP/MySQL/DNSMASQ。我只需要首先,我的虚拟主机配置可以正常工作。使用最下面的规则,我应该能够访问~/Sites文件夹中的任何网站,只要我在主机文件中为它们创建一个条目即可。

我可以访问 站点并查看我设置的根目录(或)http://localhost的索引,但无法访问 wildcard 。例如,DocumentRootVirtualDocumentServerAlias

http://test.dev在 Apache 中无法解析,尽管:

  • 它存在于我的主机文件中。
  • 能够 ping 通它。

我开始认为这个问题与 Apache 无关?也许是 DNS/IPv6 问题?

以下是netstat -amp tcp | grep 80

tcp4       0      0  192.168.0.108.49632    151.101.193.69.80      ESTABLISHED
tcp4       0      0  192.168.0.108.49608    151.101.193.69.80      ESTABLISHED
tcp6       0      0  ::1.49567              ::1.80                 CLOSE_WAIT 
tcp4       0      0  192.168.0.108.49566    192.168.0.101.8060     CLOSE_WAIT
tcp46      0      0  *.80                   *.*                    LISTEN
tcp4       0      0  127.0.0.1.18800        *.*                    LISTEN

输出sudoapachectl -v

Server version: Apache/2.4.23 (Unix)
Server built:   Dec 22 2016 18:07:11

输出cat /etc/resolv.conf

nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

输出brew services list

Name    Status  User Plist
httpd24 started elzi /Users/elzi/Library/LaunchAgents/homebrew.mxcl.httpd24.plist
jack    started elzi /Users/elzi/Library/LaunchAgents/homebrew.mxcl.jack.plist
mongodb started elzi /Users/elzi/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
mysql   started elzi /Users/elzi/Library/LaunchAgents/homebrew.mxcl.mysql.plist
php70   started elzi /Users/elzi/Library/LaunchAgents/homebrew.mxcl.php70.plist

输出sudo apachectl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server localhost (/usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf:3)
         port 80 namevhost localhost (/usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf:3)
         port 80 namevhost dev (/usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf:8)
                 wild alias *.dev
ServerRoot: "/usr/local/opt/httpd24"
Main DocumentRoot: "/Users/elzi/Sites"
Main ErrorLog: "/usr/local/var/log/apache2/error_log"
Mutex rewrite-map: using_defaults
Mutex default: dir="/usr/local/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/usr/local/var/run/apache2/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="elzi" id=501
Group: name="staff" id=20

相关内容