我尝试使用不同的虚拟主机在同一个Apache服务器(运行在Ubuntu16.04上的Apache2.4)上托管不同的网站。但是,当试图打开domain-two.tld时,服务器会传递domain-one.tld的网页。类似的行为在这和那问题中都有描述。根据我的配置文件,这两个问题的答案应该已经实现了。
虚拟主机的定义如下:
ServerName domain-one.tld
ServerAlias www.domain-one.tld
DocumentRoot /var/www/html/domain_one和
ServerName domain-two.tld
ServerAlias www.domain-two.tld
DocumentRoot /var/www/html/domain_two这两个配置文件都位于sites-available中,并通过使用指向以下目录树的a2ensite被符号链接到sites-enabled中:
sites-enabled/
|-- domain_one.conf -> ../sites-available/domain_one.conf
`-- domain_two.conf -> ../sites-available/domain_two.conf在启用配置文件之后,我重新启动apache,以便通过systemctl restart apache2重新加载配置文件。为了测试这两种配置,我在/etc/hosts文件中添加了一些额外的主机
127.0.0.1 localhost
127.0.0.1 domain-one.tld
127.0.0.1 www.domain-one.tld
127.0.0.1 domain-two.tld
127.0.0.1 www.domain-two.tld
# some further IPs down here并在本地使用curl访问两个网站。
这将按需要返回正确的文档。但是,从远程客户端Apache通过浏览器访问两个站点只提供domain_one (由于技术原因无法测试domain-two.tld,缓存在浏览器中被停用)。
这种奇怪的行为是从何而来的?我怎么能缩小范围?
因@kubanczyk的评论而更新:
curl请求而不是针对localhost的本地curl请求?对于pvz-sphere.de,即domain_one:
$ curl -v http://www.pvz-sphere.de # which is domain_one
* Rebuilt URL to: http://www.pvz-sphere.de/
* Trying 217.160.122.225...
* TCP_NODELAY set
* Connected to www.pvz-sphere.de (217.160.122.225) port 80 (#0)
> GET / HTTP/1.1
> Host: www.pvz-sphere.de
> User-Agent: curl/7.60.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Content-Length: 905
< Connection: keep-alive
< Keep-Alive: timeout=15
< Date: Wed, 06 Jun 2018 15:45:32 GMT
< Server: Apache
<
SPhERe - Symposium on Pharmaceutical Engineering Research
SPhERe - Symposium on Pharmaceutical Engineering Research
http://pvz-sphere.de/
* Connection #0 to host www.pvz-sphere.de left intact对于teresa-projekt.de,即domain_two:
$ curl -v http://www.teresa-projekt.de # which is domain_two
* Rebuilt URL to: http://www.teresa-projekt.de/
* Trying 217.160.233.207...
* TCP_NODELAY set
* Connected to www.teresa-projekt.de (217.160.233.207) port 80 (#0)
> GET / HTTP/1.1
> Host: www.teresa-projekt.de
> User-Agent: curl/7.60.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Keep-Alive: timeout=15
< Date: Wed, 06 Jun 2018 15:38:17 GMT
< Server: Apache
<
Teresa-Projekt
Teresa-Projekt
http://teresa-projekt.de/
* Connection #0 to host www.teresa-projekt.de left intact发布于 2018-07-01 16:23:34
在查看了请求和响应头以及不同的日志文件(在启用法医日志记录之后)之后,我发现域重定向(类型为iframe redirection而不是HTTP redirect)和DNS条目都是错误的。这些错误的DNS条目和重定向使得Apache交付了默认的VirtualHost,因为给定的ServerNames或ServerAlias中没有一个与请求的域匹配。
https://serverfault.com/questions/915472
复制相似问题