【问题标题】:Cant connect to VirtualDocumentRoot on local machine with apache vHosts无法使用 apache vHosts 连接到本地计算机上的 VirtualDocumentRoot
【发布时间】:2014-05-17 16:31:44
【问题描述】:

我有点卡住了。我没有让我的本地机器准备好进行开发,因为我无法让我的 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 配置的东西还不够熟悉,我可以自己弄清楚我缺少什么。也许有人可以提供有用的建议?

提前致谢。

【问题讨论】:

    标签: apache configuration port vhosts


    【解决方案1】:

    我仍然不知道问题出在哪里,但是格式化 SSD 并从头开始使用全新的 OS X 可以解决问题。同样的配置就像一个魅力。结束问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 2019-04-08
      • 2012-10-23
      相关资源
      最近更新 更多