Apache2 - mehrere Websites - VirtualHost Problem

Apache, Lighttpd, nginx, Cherokee
Post Reply
paulo-
Posts: 29
Joined: 2004-06-13 12:55
 

Apache2 - mehrere Websites - VirtualHost Problem

Post by paulo- »

Hi,

ich hab 2 websites:

example1.com
example2.com

Nun hab ich in
/etc/apache2/sites-enabled
3 Dateien:

000-default:
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

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

CustomLog /var/log/apache2/access.log combined
ServerSignature On

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>
Example1.com:
NameVirtualHost example1.com
<VirtualHost example1.com>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/web1/htdocs/example1.com/
ServerAlias http://www.example1.com

<Directory />
Options FollowSymLinks
AllowOverride All
deny from all
</Directory>
<Directory /var/www/web1/htdocs/example1.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

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

CustomLog /var/log/apache2/access.log combined
ServerSignature On

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>
Example2.com:
NameVirtualHost example2.com
<VirtualHost example2.com>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/web1/

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/web1/htdocs/example2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

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

CustomLog /var/log/apache2/access.log combined
ServerSignature On

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>
Das Problem ist, wenn ich example2.com aufrufe kommt trotzdem auch example1.com, es wird also alles zu example1.com redirected. Weis jemand Hile? Vielen Dank!
timeless2
Posts: 415
Joined: 2005-03-04 14:45
Location: Paris
 

Re: Apache2 - mehrere Websites - VirtualHost Problem

Post by timeless2 »

du verwendest vermutlich Namens-basierte VirtualHosts, d.h. für alle Domains die gleiche IP. Also darf nur einmal "NameVirtualHost" auftauchen. Du kannst dann mehrere <VirtualHost *></VirtualHost> erstellen (hier nicht deinen Domainnamen eintragen, das wäre dann IP-basiert)
In deinen VirtualHost-Einträgen fehlt auch der "ServerName", es gibt nur den ServerAlias.

http://httpd.apache.org/docs/2.0/vhosts/name-based.html
paulo-
Posts: 29
Joined: 2004-06-13 12:55
 

Re: Apache2 - mehrere Websites - VirtualHost Problem

Post by paulo- »

Hi und danke für die Antwort.

Das heißt ich muss example1.com und example2.com eigentlich in eine Datei zusammenfassen bei der ganz oben NameVirtualHost * steht und dann folgen die einzelnen VirtualHosts?

Aber wie nenn ich die einzelne Datei dann wenn nicht sites-enabled/example1.com oder sites-enabled/example2.com ?

Muss ich auch noch etwas in sites-available anlegen?

Vielen Dank!
rootsvr
Posts: 538
Joined: 2005-09-02 11:12
Contact:
 

Re: Apache2 - mehrere Websites - VirtualHost Problem

Post by rootsvr »

Normalerweise machst Du in sites-available einen Eintrag/file für jede Domain und setzt dann in sites-enabled einen symlink.

in einer der Dateien in sites-enabled (default bietet sich an) hast Du einen

Code: Select all

NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin webmaster@meinetolledomain.de
        ServerName meinetolledomain.de
        ServerAlias www.meinetolledomain.de
..
..

in den anderen (vhosts) hast Du nur noch 
<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName example.com
        ServerAlias www.example.com

..

<VirtualHost *:80>
        ServerAdmin webmaster@example1.com
        ServerName example1.com
        ServerAlias www.example1.com
es werden bei apache start alle dateien/verlinkten Dateien aus sites-enabled gestartet. Prinzip sollte klar sein: available (alle die Du konfiguriert hast) und enabled (alle die aktiv sind)

Du kannst natürlich example1 und example2 in eine Datei packen aber sinnvoll ist es da jeweils eine draus zumachen (ausser die zeigen vielleicht auf den gleichenWebspace, gehören dem selben Menschen o.ä.
Post Reply