Strona 1 z 1
[apache][vhost] problem z vhostem dla subdomeny
: 12 marca 2014, 10:56
autor: blindfox
Witam,
mam problem z konfiguracją vhostów dla 2 kont. Jedno (VH1) powinno łapać hosta
bar.foo.com na
xxx.113.8.102:80 natomiast drugie (VH2) powinno obsługiwać
foo.com oraz inne subdomeny jak
test.foo.com itp. także na na
xxx.113.8.102:80. Poniżej znajduje się konfiguracja apache
Kod: Zaznacz cały
Listen xxx.113.8.102:80
NameVirtualHost xxx.113.8.102:80
#
# bar.foo.com (VH2)
#
<VirtualHost xxx.113.8.102:80>
ServerAdmin admin@zzzzzz.com
DocumentRoot /home/bar/www
ServerName bar.foo.com
ErrorLog logs/bar.foo.com-error_log
CustomLog logs/bar.foo.com-access_log common
</VirtualHost>
#
# foo.com (VH1)
#
<VirtualHost xxx.113.8.102:80>
ServerAdmin admin@zzzzzz.com
DocumentRoot /home/foo/www
ServerName www.foo.com
ServerAlias test.foo.com *.foo.com
ErrorLog logs/www.foo.com-error_log
CustomLog logs/www.foo.com-access_log common
</VirtualHost>
Problem w tym, że
VH2 oprócz
bar.foo.com łapie mi wszystkie inne rządania na
xxx.113.8.102:80 np.
foo.com czy
xxx.foo.com .
Po usunięciu definicji
VH2,
VH1 działa OK.
Ktoś ma jakieś pomysły co mogłem popsuć?
: 12 marca 2014, 12:18
autor: Yampress
A może tak ustawisz virtualhosty metodą nazw domenowych , a nie adresów IP ?
Oczywiście musisz mieć skonfigurowany DNS i powiązane domeny z tym ip na którym stawiasz virtualhosty.
Istnieje jeszcze taka dyrektywa AliasName Poszukaj co ona robi.
: 12 marca 2014, 13:08
autor: blindfox
nie znalazłem w dokumentacji apache AliasName.
Nie wiem czy zwróciłeś uwagę na załączony fragment konfiguracji -- na moim serwerze korzystam zarówno z name jak i IP based vhost.
: 12 marca 2014, 18:03
autor: Yampress
Ale czy rozróżniasz takie dwie rzeczy?
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
http://httpd.apache.org/docs/2.2/vhosts/ip-based.html
ServerAlias zwie się
http://httpd.apache.org/docs/2.2/mod/co ... erveralias . pomyliłem słowo kluczowe.
IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host. With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. Name-based virtual hosting also eases the demand for scarce IP addresses. Therefore you should use name-based virtual hosting unless you are using equipment that explicitly demands IP-based hosting. Historical reasons for IP-based virtual hosting based on client support are no longer applicable to a general-purpose web server, unless you are using amod_sslversion without SNI support (standard in Apache releases since 2.2.12).
To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using theNameVirtualHostdirective. In the normal case where any and all IP addresses on the server should be used, you can use*
as the argument toNameVirtualHost. If you're planning to use multiple ports (e.g. running SSL) you should add a Port to the argument, such as*:80
. Note that mentioning an IP address in aNameVirtualHostdirective does not automatically make the server listen to that IP address. SeeSetting which addresses and ports Apache usesfor more details. In addition, any IP address specified here must be associated with a network interface on the server.The next step is to create a<VirtualHost>block for each different host that you would like to serve. The argument to the<VirtualHost>directive must match a definedNameVirtualHostdirective. (In this usual case, this will be "*:80"). Inside each<VirtualHost>block, you will need at minimum aServerNamedirective to designate which host is served and aDocumentRootdirective to show where in the filesystem the content for that host lives.]
: 13 marca 2014, 08:04
autor: blindfox
rozróżniam.
W załączonym fragmencie configu znajdują się następujące wiersze dotyczące name-based vhost:
NameVirtualHost xxx.113.8.102:80
VH2:
ServerName bar.foo.com
VH1:
ServerName www.foo.com
ServerAlias test.foo.com *.foo.com
Ponieważwystępują subdomeny
foo.com skierowane na tą samą maszyną ale na inne IP niż xxx.113.8.102:80, w moim configu występują także fragmenty odpowiadające za IP-based vhost:
VH2:
<VirtualHost xxx.113.8.102:80>
VH1:
<VirtualHost xxx.113.8.102:80>
: 13 marca 2014, 09:22
autor: Yampress
NameVirtualHost *:80
VH2:
<VirtualHost *:80>
VH1:
<VirtualHost *:80>