无法使用apache vHosts连接到本地计算机上的VirtualDocumentRoot

时间:2014-04-05 08:22:06

标签: apache configuration port vhosts

我有点卡住了。我没有准备好开发我的本地机器因为我无法使我的vHost配置正常工作。我只是无法使用浏览器访问我的文档根目录(连接失败。可以连接到服务器)。

详细说明:

OS: OSX 10.9.2
Apache/2.2.26

vHost配置如下所示:

<VirtualHost *:80>
  ServerAdmin me@something.com
  ServerName something.loc
  ServerAlias *.someting.loc
  UseCanonicalName Off
  VirtualDocumentRoot /path/to/vhosts/%2/%1/htdocs
  <IfModule dir_module>
        DirectoryIndex index.php index.html
  </IfModule>
  <FilesMatch "\.js\.gzip$">
        AddType "text/javascript" .js.gzip
  </FilesMatch>
  <FilesMatch "\.css\.gzip$">
        AddType "text/css" .css.gzip
  </FilesMatch>
  AddEncoding x-gzip .gzip
  <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain text/html
  </IfModule>
</virtualHost>

/path/to/vhosts/test/dev/htdocs中,我有一个简单的index.html,即“Hello World!”。 应与此文件夹匹配的主机是dev.test.something.loc,我将其包含在/etc/hosts中:

127.0.0.1   dev.test.something.loc

已加载mod_vhost_alias apache模块:

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

所以我无法通过浏览器访问index.html,但尝试时我在apache error.log中没有得到任何内容。所以让我们试试wget:

$ wget dev.test.something.loc
--2014-04-05 10:12:40--  http://dev.test.something.loc/
Resolving dev.test.something.loc... 127.0.0.1
Connecting to dev.test.something.loc|127.0.0.1|:80... failed: Connection refused.

好的,不工作。下一步方法:

wget --header="Host: dev.test.something.loc" -O - http://localhost
--2014-04-05 10:14:53--  http://localhost/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 67 [text/html]
Saving to: 'STDOUT'

 0% [                         ] 0           --.-K/s              <html>
<head>
</head>
<body>
<h1>Hello World!</h1>
</body>

</html>
100%[============================>] 67          --.-K/s   in 0s

2014-04-05 10:14:53 (5.32 MB/s) - written to stdout [67/67]

看,那是我的index.html!让我们尝试127.0.0.1而不是localhost:

wget --header="Host: dev.test.something.loc" -O - 127.0.0.1
--2014-04-05 10:17:24--  http://127.0.01/
Resolving 127.0.0.1... 127.0.0.1
Connecting to 127.0.0.1|127.0.0.1|:80... failed: Connection refused.

这就是我到目前为止所做的一切。有些事情显然是错的。但是我对整个apache配置的东西不够熟悉,我可以自己想象我错过了什么。也许有人可以提供有用的建议?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我仍然不知道问题是什么,但是格式化SSD并从头开始使用新的OS X完成了这项工作。同样的配置就像一个魅力。结束这个问题。