繁体   English   中英

Apache2 虚拟主机配置:显示错误页面

[英]Apache2 virtual host configuration: Wrong pages showing

我有 4 个域:foo.eu、foo.net、bar.eu、bar.de。 我有一台虚拟服务器,运行 Ubuntu 12.04 LTS 和 Apache2。

我想托管 3 个不同的网页,映射如下:

  • 第 1 页:foo.eu 和 foo.net
  • 第 2 页:bar.eu 和 bar.de
  • 第 3 页:sub.foo.eu

问题是当我访问“www.foo.eu”、“sub.foo.eu”或“www.bar.eu”时,我会显示正确的页面,但是如果我访问“bar.eu”的“foo.eu” " 我看到了 "sub.foo.eu" 的页面。

为什么“foo.eu”/“bar.eu”显示的内容与“www.foo.eu”/“www.bar.eu”不一样?

我的 /etc/apache2/sites-available/ 中有以下文件:

foo.eu:

<VirtualHost *:80>
DocumentRoot /var/www/foo

ServerName foo.eu
ServerName www.foo.eu

ServerAdmin webmaster@foo.eu

<Directory /var/wwww/foo >
    Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/foo_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/foo_access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

foo.net 类似,只是调整了 SeverName 行。

sub.foo.eu:

<VirtualHost *:80>

ServerName sub.foo.eu
ServerAlias sub.foo.eu

RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

DocumentRoot /var/www/sub/

ErrorLog ${APACHE_LOG_DIR}/sub_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/sub_access.log combined

<Directory /var/www/owncloud>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        order allow,deny
        allow from all
</Directory>
</VirtualHost>

<VirtualHost *:443>

ServerName sub.steiler.eu
ServerAlias sub.steiler.eu

SSLEngine on
SSLCertificateFile /etc/ssl/crt/sub-cert.pem
SSLCACertificateFile /etc/ssl/crt/caCert.pem
SSLCertificateKeyFile /etc/ssl/key/sub-key.pem

DocumentRoot /var/www/sub/

ErrorLog ${APACHE_LOG_DIR}/sub_ssl_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/sub_ssl_access.log combined

<Directory /var/www/sub>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

</VirtualHost>

bar.eu:

<VirtualHost *:80>
DocumentRoot /var/www/bar

ServerName bar.de
ServerName www.bar.de

ServerAdmin webmaster@bar.de

<Directory /var/wwww/bar >
    Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/bar_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/bar_access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

bar.de 类似,只是调整了 SeverName 行。

更新:以下是对域的 DNS 查询:

域之一(foo.eu;foo.net 类似):

~dig foo.eu A

; <<>> DiG 9.9.3-rl.156.01-P1-RedHat-9.9.3-3.P1.fc19 <<>> steiler.eu A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2157
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
foo.eu.                    IN      A

;; ANSWER SECTION:
foo.eu.                 86306   IN      A       192.168.178.1

;; AUTHORITY SECTION:
steiler.eu.             86306   IN      NS      ns-de.1and1-dns.biz.
steiler.eu.             86306   IN      NS      ns-de.1and1-dns.de.
steiler.eu.             86306   IN      NS      ns-de.1and1-dns.com.
steiler.eu.             86306   IN      NS      ns-de.1and1-dns.org.

;; Query time: 3 msec
;; SERVER: 15.8.243.101#53(15.8.243.101)
;; WHEN: Thu Jun 26 09:05:52 PDT 2014
;; MSG SIZE  rcvd: 186

子域(sub.foo.eu):

~ dig sub.foo.eu A

; <<>> DiG 9.9.3-rl.156.01-P1-RedHat-9.9.3-3.P1.fc19 <<>> owncloud.steiler.eu
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7371
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 7

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;owncloud.steiler.eu.           IN      A

;; ANSWER SECTION:
sub.foo.eu.             86400   IN      A       192.168.178.1

;; AUTHORITY SECTION:
foo.eu.                 86004   IN      NS      ns-de.1and1-dns.biz.
foo.eu.                 86004   IN      NS      ns-de.1and1-dns.org.
foo.eu.                 86004   IN      NS      ns-de.1and1-dns.com.
foo.eu.                 86004   IN      NS      ns-de.1and1-dns.de.

;; ADDITIONAL SECTION:
ns-de.1and1-dns.de.     3204    IN      A       217.160.80.1
ns-de.1and1-dns.de.     3600    IN      AAAA    2001:8d8:fe:53:0:d9a0:5001:100
ns-de.1and1-dns.biz.    3204    IN      A       217.160.81.1
ns-de.1and1-dns.biz.    3600    IN      AAAA    2001:8d8:fe:53:0:d9a0:5101:100
ns-de.1and1-dns.com.    3204    IN      A       217.160.82.1
ns-de.1and1-dns.org.    3204    IN      A       217.160.83.1

;; Query time: 101 msec
;; SERVER: 15.8.243.101#53(15.8.243.101)
;; WHEN: Thu Jun 26 09:10:54 PDT 2014
;; MSG SIZE  rcvd: 315

另一个域(bar.de;bar.eu 类似):

~dig bar.de A

; <<>> DiG 9.9.3-rl.156.01-P1-RedHat-9.9.3-3.P1.fc19 <<>> steilerdev.de A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13963
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 9

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;bar.de.                 IN      A

;; ANSWER SECTION:
bar.de.                 86393   IN      A       192.168.178.1

;; AUTHORITY SECTION:
bar.de.                 86393   IN      NS      ns-de.1and1-dns.de.
bar.de.                 86393   IN      NS      ns-de.1and1-dns.org.
bar.de.                 86393   IN      NS      ns-de.1and1-dns.biz.
bar.de.                 86393   IN      NS      ns-de.1and1-dns.com.

;; ADDITIONAL SECTION:
ns-de.1and1-dns.de.     2943    IN      A       217.160.80.1
ns-de.1and1-dns.de.     3339    IN      AAAA    2001:8d8:fe:53:0:d9a0:5001:100
ns-de.1and1-dns.biz.    2943    IN      A       217.160.81.1
ns-de.1and1-dns.biz.    3339    IN      AAAA    2001:8d8:fe:53:0:d9a0:5101:100
ns-de.1and1-dns.com.    2943    IN      A       217.160.82.1
ns-de.1and1-dns.com.    3339    IN      AAAA    2001:8d8:fe:53:0:d9a0:5201:100
ns-de.1and1-dns.org.    2943    IN      A       217.160.83.1
ns-de.1and1-dns.org.    3339    IN      AAAA    2001:8d8:fe:53:0:d9a0:5301:100

;; Query time: 2 msec
;; SERVER: 15.8.243.101#53(15.8.243.101)
;; WHEN: Thu Jun 26 09:15:15 PDT 2014
;; MSG SIZE  rcvd: 363

PS:我换了IP。

PPS: www.foo.euwww.bar.de的查询与上述相同。

虽然我绝不是 DNS 专家,但我会建议一些事情。

  • 如果您的 foo.eu 和 sub.foo.eu 都指向同一个 IP 地址,只需删除您的 sub.foo.eu DNS 信息。 彻底摆脱它。 让 Apache 处理这些请求。 可以肯定的是,您也可以使用 Apache 来处理服务器外部的请求。 长话短说...不要使用 DNS 记录来设置子域。

  • 如果这破坏了某些内容,请查看子域的 CNAME。 您应该能够将 foo.eu 重定向到 www.foo.eu,这同样适用于 var.eu。

  • 您没有在大多数记录中使用 ServerAlias。 您改为使用两个 ServerNames。 第二个将覆盖。 这可能是您问题的焦点。 如果Apache没有设置ServerAlias,那么它就会被迫猜测。 如果这反映了您的配置,那么它将执行反向 DNS 查找。 您可以在 ServerAlias 上查看 Apache 文档以了解更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM