Anfängerfrage: alle virtuellen Hosts zeigen gleiche Seite

Alles, was den Apache betrifft, kann hier besprochen werden.

Anfängerfrage: alle virtuellen Hosts zeigen gleiche Seite

Postby glaskugel » 26. October 2008 11:23

Vorbemerkung: Es hat schon funktioniert und ich habe vermutlich nur eine Kleinigkeit verstellt. Hoffentlich ist es kein Cache-Problem.

Es geht um apache2-2.2.4-70.4 auf einem Opensuse 10.3 System.

Das Testszenario sollte aus 3 unterschiedlichen Seiten bestehen und jede Seite sollte einen anderen Inhalt anzeigen.

Code: Select all
rcapache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate)         done
Starting httpd2 (prefork)                                            done


Die Pfade sollte also stimmen, sonst würde eine Fehlermeldung kommen.

Das habe ich konfiguriert.


Code: Select all
#/etc/apache2/default-server.conf
# alles default bis auf letzte Zeile
DocumentRoot "/srv/www/htdocs"
<Directory "/srv/www/htdocs">
Options None
AllowOverride None
Order allow,deny
 Allow from all
</Directory>
Alias /icons/ "/usr/share/apache2/icons/"
<Directory "/usr/share/apache2/icons">
 Options Indexes MultiViews
 AllowOverride None
 Order allow,deny
 Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
<Directory "/srv/www/cgi-bin">
 AllowOverride None
 Options +ExecCGI -Includes
 Order allow,deny
 Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir public_html
Include /etc/apache2/mod_userdir.conf
</IfModule>
Include /etc/apache2/conf.d/*.conf
Include /etc/apache2/conf.d/apache2-manual?conf
        NameVirtualHost 192.168.2.100


Es wurden also 2 virtuelle Hosts angelegt
Code: Select all
#/etc/apache2/vhosts.d/vhost.conf
<VirtualHost 192.168.2.100>
 DocumentRoot /srv/www/htdocs/crystalball.site
 servername crystalball.site
 DocumentRoot /srv/www/htdocs/glaskugel.site
 servername glaskugel.site
</VirtualHost>


Das sollte erscheinen, wenn 192.168.2.100 aufgerufen wird:
Code: Select all
cat /srv/www/htdocs/index.html
<html><body><h1>It works!</h1></body></html>


Diese Seie habe ich schon gesehen:
Code: Select all
cat /srv/www/htdocs/crystalball.site/index.html
<html>
  <head>
    <title></title>
    <meta content="">
    <style></style>
  </head>
  <body>crytalball works</body>
</html>


Diese Seite kommt immer:
Code: Select all
cat /srv/www/htdocs/glaskugel.site/index.html
<html>
  <head>
    <title></title>
    <meta content="">
    <style></style>
  </head>
  <body>Glaskugel ok</body>
</html>
glaskugel
 
Posts: 21
Joined: 26. October 2008 00:23

Postby glitzi85 » 26. October 2008 16:36

Tja, als erstes solltest du mal in der httpd.conf noch die vhosts.conf includieren, sonst wird das nichts.

Dann sollte der Übersicht halber das NameVirtualHost auch noch in die vhosts.conf. Außerdem muss die so aussehen:

Code: Select all
#/etc/apache2/vhosts.d/vhost.conf

NameVirtualHost 192.168.2.100

<VirtualHost 192.168.2.100>
 DocumentRoot /srv/www/htdocs
 ServerName localhost
</VirtualHost>

<VirtualHost 192.168.2.100>
 DocumentRoot /srv/www/htdocs/crystalball.site
 servername crystalball.site
</VirtualHost>

<VirtualHost 192.168.2.100>
 DocumentRoot /srv/www/htdocs/glaskugel.site
 servername glaskugel.site
</VirtualHost>


Dann entweder die vhosts.conf nach /etc/apache2/conf.d/vhosts.conf verschieben oder eine Include-Anweisung in die httpd.conf packen.

mfg glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby glaskugel » 26. October 2008 19:03

/etc/apache2/httpd.conf
Include /etc/apache2/vhosts.d/*.conf


/etc/apache2/vhosts.d/vhost.conf
enthält genau deinen Vorschlag

Nach rcapache2 restart

sehe ich überall die Seite "it works", d.h. /srv/www/htdocs/index.html

und nicht die Seiten der virtuellen Hosts.
glaskugel
 
Posts: 21
Joined: 26. October 2008 00:23

Postby glitzi85 » 27. October 2008 13:39

Was mir grad noch einfällt:

/srv/www/htdocs/crystalball.site und /srv/www/htdocs/glaskugel.site sind schon Ordner und keine Dateien, oder? Du kannst im DocumentRoot nämlich keine Dateien angeben, sondern nur Ordner.

mfg glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Re: Anfängerfrage: alle virtuellen Hosts zeigen gleiche Seit

Postby Nobbie » 27. October 2008 22:46

glaskugel wrote:Es wurden also 2 virtuelle Hosts angelegt
Code: Select all
#/etc/apache2/vhosts.d/vhost.conf
<VirtualHost 192.168.2.100>
 DocumentRoot /srv/www/htdocs/crystalball.site
 servername crystalball.site
 DocumentRoot /srv/www/htdocs/glaskugel.site
 servername glaskugel.site
</VirtualHost>


So funktioniert das nicht - Du kannst pro VirtualHost nur einen Servername und einen DocumentRoot angeben. Du hast nicht 2 virtuelle Hosts angelegt, sondern einen einzigen kaputten.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Postby glaskugel » 28. October 2008 09:23

@glitzi85: Ja es sind Ordner

@Nobbie: Ich glaube euch das schon und habe es auch so gemacht wie es glitzi85 angeführt hat. "Irgendwie" hatten unterschiedliche vhosts aber so funktioniert, wenn auch nicht alles, so wie es sein voll. Ich bin nach dieser Anleitung vorgegangen: http://www.swerdna.net.au/linhowtoapache.html und hatte "additional directives here" falsch interpretiert.

Ich habe gerade den Apache noch einmal neu gesteartet und nun gibt es eine Fehlermeldung

Code: Select all
# rcapache2 restart
[Tue Oct 28 10:18:12 2008] [warn] NameVirtualHost 192.168.2.100:0 has no VirtualHosts
Syntax OK
Shutting down httpd2 (waiting for all children to terminate)         done
Starting httpd2 (prefork) [Tue Oct 28 10:18:12 2008] [warn] NameVirtualHost 192.168.2.100:0 has no VirtualHosts
glaskugel
 
Posts: 21
Joined: 26. October 2008 00:23

Postby glitzi85 » 28. October 2008 15:05

Die Fehlermeldung interpretier ich mal so:
Du hast die NameVirtualHost-Direktive immer noch in der httpd.conf drin aber das Include funktioniert nicht.

Dann tritt nämlich der Fall auf, dass NameVirtualHost aktiviert ist, er aber keine vHost-Blöcke findet. Dann kommt genau die Fehlermeldung die du gepostet hast.

mfg glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby glaskugel » 28. October 2008 15:51

Sorry, mir sind die Zusammehänge noch zu kompliziert.

Vielleicht kann man daraus etwas erkennen:

Code: Select all
# grep -r -i NameVirtualHost /etc/apache2/
/etc/apache2/listen.conf:#NameVirtualHost 12.34.56.78:80
/etc/apache2/listen.conf:#NameVirtualHost *:80
/etc/apache2/listen.conf:#NameVirtualHost *
/etc/apache2/vhosts.d/vhost-ssl.template:# NameVirtualHost statements should be added to /etc/apache2/listen.conf.
/etc/apache2/vhosts.d/vhost.template:# NameVirtualHost statements can be added to /etc/apache2/listen.conf.
/etc/apache2/vhosts.d/vhost.conf:NameVirtualHost 192.168.2.100
/etc/apache2/default-server.conf:       NameVirtualHost 192.168.2.100


Ich habe die auskommentierten gelassen. Vielleicht sollte hier etwas aktiviert werden?

Code: Select all
# grep -r -i include /etc/apache2/
/etc/apache2/conf.d/phpmyadmin.conf:php_admin_flag allow_url_include off
/etc/apache2/errors.conf:# includes to substitute the appropriate text.
/etc/apache2/errors.conf:#   Alias /error/include/ "/your/include/path/"
/etc/apache2/errors.conf:# /usr/share/apache2/error/include/ files and copying them to /your/include/path/,
/etc/apache2/errors.conf:# even on a per-VirtualHost basis.  The default include files will display
/etc/apache2/errors.conf:# The internationalized error documents require mod_alias, mod_include
/etc/apache2/errors.conf:<IfModule mod_include.c>
/etc/apache2/errors.conf:        Options IncludesNoExec
/etc/apache2/errors.conf:        AddOutputFilter Includes html
/etc/apache2/httpd.conf:# If possible, avoid changes to this file. It does mainly contain Include
/etc/apache2/httpd.conf:# Overview of include files, chronologically:
/etc/apache2/httpd.conf:#  |-- sysconfig.d/include.conf  . . . . . .  [*] your include files
/etc/apache2/httpd.conf:#  |                                             (for each file to be included here, put its name
/etc/apache2/httpd.conf:#  |                                              into APACHE_INCLUDE_* in /etc/sysconfig/apache2)
/etc/apache2/httpd.conf:#       `-- *.conf . . . . . . . . . . . . .     (*.conf is automatically included)
/etc/apache2/httpd.conf:#  |   |-- include.conf
/etc/apache2/httpd.conf:Include /etc/apache2/uid.conf
/etc/apache2/httpd.conf:Include /etc/apache2/server-tuning.conf
/etc/apache2/httpd.conf:Include /etc/apache2/sysconfig.d/loadmodule.conf
/etc/apache2/httpd.conf:Include /etc/apache2/listen.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_log_config.conf
/etc/apache2/httpd.conf:Include /etc/apache2/sysconfig.d/global.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_status.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_info.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_usertrack.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_autoindex-defaults.conf
/etc/apache2/httpd.conf:Include /etc/apache2/mod_mime-defaults.conf
/etc/apache2/httpd.conf:Include /etc/apache2/errors.conf
/etc/apache2/httpd.conf:Include /etc/apache2/ssl-global.conf
/etc/apache2/httpd.conf:Include /etc/apache2/default-server.conf
/etc/apache2/httpd.conf:# Another way to include your own files
/etc/apache2/httpd.conf:# include arbitrary files as named in APACHE_CONF_INCLUDE_FILES and
/etc/apache2/httpd.conf:# APACHE_CONF_INCLUDE_DIRS
/etc/apache2/httpd.conf:Include /etc/apache2/sysconfig.d/include.conf
/etc/apache2/httpd.conf:Include /etc/apache2/vhosts.d/*.conf
/etc/apache2/httpd.conf:#       putting its name into APACHE_CONF_INCLUDE_FILES in
/etc/apache2/mod_mime-defaults.conf:# To parse .shtml files for server-side includes (SSI):
/etc/apache2/mod_mime-defaults.conf:# (You will also need to add "Includes" to the "Options" directive.)
/etc/apache2/mod_mime-defaults.conf:#AddOutputFilter INCLUDES .shtml
/etc/apache2/mod_userdir.conf:          Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
/etc/apache2/server-tuning.conf:# a directory that does not include the trailing slash.  This fixes a
/etc/apache2/sysconfig.d/loadmodule.conf:LoadModule include_module                 /usr/lib/apache2-prefork/mod_include.so
/etc/apache2/sysconfig.d/include.conf:# as listed in APACHE_INCLUDE_* (/etc/sysconfig/apache2)
/etc/apache2/vhosts.d/vhost.template:    # Optionally, include *.conf files from /etc/apache2/conf.d/
/etc/apache2/vhosts.d/vhost.template:    # Include /etc/apache2/conf.d/mod_php4.conf
/etc/apache2/vhosts.d/vhost.template:    # or, to include all configuration snippets added by packages:
/etc/apache2/vhosts.d/vhost.template:    # Include /etc/apache2/conf.d/*.conf
/etc/apache2/vhosts.d/vhost.template:   Options +ExecCGI -Includes
/etc/apache2/vhosts.d/vhost.template:   Include /etc/apache2/mod_userdir.conf
/etc/apache2/vhosts.d/vhost.template:   #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
/etc/apache2/default-server.conf:       #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
/etc/apache2/default-server.conf:# Note that if you include a trailing / on fakename then the server will
/etc/apache2/default-server.conf:# We include the /icons/ alias for FancyIndexed directory listings.  If you
/etc/apache2/default-server.conf: Options +ExecCGI -Includes
/etc/apache2/default-server.conf:Include /etc/apache2/mod_userdir.conf
/etc/apache2/default-server.conf:# Include all *.conf files from /etc/apache2/conf.d/.
/etc/apache2/default-server.conf:# You can comment this out here if you want those bits include only in a
/etc/apache2/default-server.conf:Include /etc/apache2/conf.d/*.conf
/etc/apache2/default-server.conf:Include /etc/apache2/conf.d/apache2-manual?conf
glaskugel
 
Posts: 21
Joined: 26. October 2008 00:23

Postby glitzi85 » 28. October 2008 17:41

Sollte eigentlich funktionieren. Die NameVirtualHost-Direktive ist zwar zweimal drin (/etc/apache2/default-server.conf und /etc/apache2/vhosts.d/vhost.conf), aber das sollte glaub trotzdem funktionieren. Nimm auf jeden Fall mal eine raus.

Welche Dateien werden denn aus /etc/apache2/vhosts.d/ noch inkludiert? Evtl. stösst da was zusammen.

mfg glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim


Return to Apache

Who is online

Users browsing this forum: No registered users and 17 guests