本地apache无法解析vhost

时间:2018-06-18 09:59:23

标签: apache vhosts

我在我的Mac(macOS 10.13.5)上使用Homebrew设置了一个本地Apache(2.4.33)。服务器正在运行,配置文件的语法检查返回“语法正常”。 我已经在httpd-vhosts.conf文件(/usr/local/etc/httpd/extra/httpd-vhosts.conf)中为我的DEV环境定义了几个虚拟主机,并检查了这个文件是否实际加载了:

httpd -D DUMP_INCLUDES
Included configuration files:
(*) /usr/local/etc/httpd/httpd.conf
(542) /usr/local/etc/httpd/extra/httpd-vhosts.conf

我做了另一项检查,以确保Vhost配置是否也正常:

httpd -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:40)
     port 80 namevhost localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:40)
     port 80 namevhost spielwiese.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:45)
     port 80 namevhost phpmyadmin.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:77)
     port 80 namevhost relaunch.domain1.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:85)
     port 80 namevhost dev.domain2.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:93)
     port 80 namevhost test.domain2.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:101)

到目前为止看起来很有希望。奇怪的是,所有的vhost都可以解析,但是两个(dev.domain2.local& test.domain2.local)可以解析,我在配置中找不到错误:

<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/phpmyadmin"
ServerName phpmyadmin.local
ErrorLog "/private/var/log/apache2/phpmyadmin.local-error_log"
CustomLog "/private/var/log/apache2/phpmyadmin.local-access_log" common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/username/owncloud/somefolder/www/relaunch.domain1.local/public_html"
ServerName relaunch.domain1.local
ErrorLog "/private/var/log/apache2/relaunch.domain1.local-error_log"
CustomLog "/private/var/log/apache2/relaunch.domain1.local-access_log" common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/dev.domain2.local/web"
ServerName dev.domain2.local
ErrorLog "/private/var/log/apache2/dev.domain2.local-error_log"
CustomLog "/private/var/log/apache2/dev.domain2.local-access_log" common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/test.domain2.local"
ServerName test.domain2.local
ErrorLog "/private/var/log/apache2/test.domain2.local-error_log"
CustomLog "/private/var/log/apache2/test.domain2.local-access_log" common
</VirtualHost>

我已多次停止,启动并重新启动apache,但总是得到相同的结果:

$ ping phpmyadmin.local
PING phpmyadmin.local (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.040 ms
$ ping test.domain2.local
ping: cannot resolve test.domain2.local: Unknown host
$ ping dev.domain2.local
ping: cannot resolve dev.domain2.local: Unknown host

任何想法或提示如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题解决了 - 感谢@ dusan-bajic!将这两个域添加到/ etc / hosts文件后,一切都按预期工作。