#ubuntu #apache2 #virtualhost #vps #subdomain
#ubuntu #apache2 #virtualhost #vps #поддомен
Вопрос:
У меня есть 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 «Мне отображается правильная страница, но если я получу доступ»foo.eu » из «bar.eu » Я вижу страницу «sub.foo.eu «.
Почему нет «foo.eu «/»bar.eu » показывает мне то же содержание , что и «www.foo.eu «/»www.bar.eu «?
У меня есть следующие файлы в моем /etc/apache2/sites-доступны/:
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 is similar, just the SeverName lines are adjusted.
UPDATE: Here are the DNS queries to the domains:
One of the domains (foo.eu; foo.net is similar):
~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
The subdomain (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.
P.P.S.: запросы для www.foo.eu и www.bar.de равны приведенным выше.
Комментарии:
1. Вы проверили свои записи A для своих доменных имен?
2. Все записи 5 A указывают на один и тот же IP-адрес. Или что еще я должен там проверить?
3. Не могли бы вы вставить свои столбцы? Вы можете подвергнуть цензуре IP-адрес, но было бы полезно просмотреть вашу конфигурацию.
4. Я отредактировал исходное сообщение и добавил свою конфигурацию DNS.
Ответ №1:
Хотя я ни в коем случае не эксперт по DNS, я бы посоветовал несколько вещей.
-
Если ваш foo.eu и sub.foo.eu если оба указывают на один и тот же IP-адрес, просто сотрите свой sub.foo.eu Информация DNS. Полностью избавьтесь от него. Пусть Apache обрабатывает эти запросы. Вполне вероятно, что вы также можете использовать Apache для обработки запросов за пределами вашего сервера. Короче говоря… Не используйте записи DNS для установки поддомена.
-
Если это что-то нарушает, взгляните на CNAMEs для поддоменов. Вы должны иметь возможность перенаправлять foo.eu чтобы www.foo.eu , и то же самое относится к var.eu .
-
Вы не используете ServerAlias в большинстве своих записей. Вместо этого вы используете два имени сервера. Второе переопределит. Вероятно, это основная проблема вашей проблемы. Если Apache не устанавливает ServerAlias, он будет вынужден угадать. Если это отражает вашу конфигурацию, тогда будет выполнен обратный поиск DNS. Вы можете ознакомиться с документацией Apache по ServerAlias для получения дополнительной информации.