ServerAlias www.example.com 无法识别
下面是我的配置文件:
NameVirtualHost 12.34.56.78:80
<VirtualHost 12.34.56.78:80>
ServerAdmin [email protected]
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /srv/www/domain1.com/public_html1/
ErrorLog /srv/www/domain1.com/logs/error.log
CustomLog /srv/www/domain1.com/logs/access.log combined
</VirtualHost>
<VirtualHost 12.34.56.78:80>
ServerAdmin [email protected]
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /srv/www/domain2.com/public_html1/
ErrorLog /srv/www/domain2.com/logs/error.log
CustomLog /srv/www/domain2.com/logs/access.log combined
</VirtualHost>
问题是当我将 www.domain1.com
放入浏览器时,apache2 不会检索驻留在 /srv/www/domain1.com/public_html1 中的网页/
相反,它从另一个文件中定义的默认文档根获取页面。但是,如果我输入 www.domain2.com
,一切正常。我没有看到两个 VirtualHost 配置块之间有任何区别,所以我想知道是什么造成了区别。顺便说一句,我没有在其文档根目录下放置任何 .htaccess
文件。
Below is my config file:
NameVirtualHost 12.34.56.78:80
<VirtualHost 12.34.56.78:80>
ServerAdmin [email protected]
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /srv/www/domain1.com/public_html1/
ErrorLog /srv/www/domain1.com/logs/error.log
CustomLog /srv/www/domain1.com/logs/access.log combined
</VirtualHost>
<VirtualHost 12.34.56.78:80>
ServerAdmin [email protected]
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /srv/www/domain2.com/public_html1/
ErrorLog /srv/www/domain2.com/logs/error.log
CustomLog /srv/www/domain2.com/logs/access.log combined
</VirtualHost>
The thing is when I put www.domain1.com
into browser, apache2 doesn't retrieve the web page resides in /srv/www/domain1.com/public_html1/
, instead, it gets the page from the default document root defined in another file. However, if I put www.domain2.com
, everything works fine. I don't see any difference between two VirtualHost config block, so I wonder what does make the difference. BTW, I haven't put any .htaccess
file under their document root.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试通过发出以下命令来检查您的 Apache 配置:
我猜你的“默认”虚拟主机使用“www.domain1.com”作为其服务器名称,因此它响应对“www.domain1.com”的请求。
在我的机器上发生这种情况是因为“www.domain1.com”是我机器的主机名。如果未指定 ServerName,Apache 会尝试猜测 - 导致上述问题。
我通过在站点可用/默认中指定“ServerName default”解决了这个问题。
这也可能有一些帮助:
http://httpd.apache.org/文档/current/dns-caveats.html
Try checking your Apache config by issuing:
I guess your "default" virtual host uses "www.domain1.com" as its ServerName, thus it responds to the request to "www.domain1.com".
On my machine this happened due to "www.domain1.com" being my machine's hostname. If ServerName is not specified, Apache tries to guess - causing the abovementioned problem.
I solved this by specifying "ServerName default" in sites-available/default.
This might be of some help as well:
http://httpd.apache.org/docs/current/dns-caveats.html
如果您使用的是 Windows 并且可能使用 ZendSever,那么您必须执行以下操作:
打开目录“C:\Windows\System32\drivers\etc”中的文件“hosts”
添加
127.0.0.1 www.domain1.com
下
在127.0.0.1 localhost
127.0.0.1 domain1.com
它应该如下所示:
127.0.0.1 localhost
127.0.0.1 domain1.com
127.0.0.1 www.domain1.com
127.0.0.1 domain2.com
127.0.0.1 www.domain2.com
127.0.0.1 domain3.com
127.0.0.1 www.domain3.com
所有域名都需要在此文件中注册。
If you are on Windows and probably using a ZendSever, than you MUST do next:
Open file "hosts" in directory "C:\Windows\System32\drivers\etc"
Add
127.0.0.1 www.domain1.com
under
127.0.0.1 localhost
127.0.0.1 domain1.com
It should look like this:
127.0.0.1 localhost
127.0.0.1 domain1.com
127.0.0.1 www.domain1.com
127.0.0.1 domain2.com
127.0.0.1 www.domain2.com
127.0.0.1 domain3.com
127.0.0.1 www.domain3.com
All domains need to be registered in this file.
只是想说,这也让我感到困惑,并且更改默认 apache 站点中的 ServerName 对我有用,就像简单地使用禁用该站点一样
然后重新加载apache。
Just wanted to say that this caught me out too, and changing the ServerName in the default apache site worked for me, as did simply disabling that site using
Then reloading apache.