Dies ist eine alte Version des Dokuments!
Vorraussetzung: apache, bind und dns
Achtung: in der Apache-Konfiguration ist die Reihenfolge wichtig.
Die Namen aller Virtual Hosts müssen im DNS eingetragen sein, fehlende wie unter bind gezeigt hinzufügen
getent hosts notebook14.linuxhotel.de getent hosts iw.linuxhotel.de
/etc/apache2/listen.conf : (SuSE bis 12.3 )
NameVirtualHost *
/etc/apache2/conf.d/default_vhost.conf : ( SuSE ab 10.2 )
<VirtualHost *> </VirtualHost>
/etc/apache2/vhosts.d/iw.linuxhotel.de.conf : ( SuSE ab 10.2 )
<VirtualHost *>
ServerName iw.linuxhotel.de
DocumentRoot /srv/www/iw.linuxhotel.de/htdocs
<Directory "/srv/www/iw.linuxhotel.de/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
apache2ctl configtest apache2ctl -S
/srv/www/htdocs/test.html : ( SuSE ab 10.2 )
<html>
<head>
<title>Default Host notebook34!</title>
</head>
<body>
Default Host notebook34<br/>
<a href="http://iw.linuxhotel.de/test.html">Virtual Host</a>
</body>
</html>
mkdir -p /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs}
/srv/www/iw.linuxhotel.de/htdocs/test.html : ( SuSE ab 10.2 )
<html>
<head>
<title>Virtual Host iw!</title>
</head>
<body>
Virtual Host iw<br/>
<a href="http://notebook34.linuxhotel.de/test.html">Default Host</a>
</body>
</html>
/etc/httpd/conf/httpd.conf: ( Centos 5 )
ServerAdmin root@notebook14.linuxhotel.de ServerName notebook14.linuxhotel.de DocumentRoot /var/www/html <Directory "/var/www/html"> Order allow,deny Allow from all </Directory> ErrorLog logs/error_log CustomLog logs/access_log combined NameVirtualHost * <VirtualHost *:80> </VirtualHost> Include vhosts.d/*.conf
mkdir vhosts.d
/etc/httpd/vhosts.d/iw.linuxhotel.de.conf : ( Centos 5 )
<VirtualHost *:80>
ServerName iw.linuxhotel.de
DocumentRoot /var/www/iw.linuxhotel.de/html
<Directory "/var/www/iw.linuxhotel.de/html">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
apachectl configtest apachectl -S
/var/www/html/test.html : ( Centos 5 )
<html>
<head>
<title>Default Host notebook34!</title>
</head>
<body>
Default Host notebook34<br/>
<a href="http://iw.linuxhotel.de/test.html">Virtual Host</a>
</body>
</html>
mkdir /var/www/iw.linuxhotel.de/{cgi-bin,html}
/var/www/iw.linuxhotel.de/html/test.html : ( Centos 5 )
<html>
<head>
<title>Virtual Host iw!</title>
</head>
<body>
Virtual Host iw<br/>
<a href="http://notebook34.linuxhotel.de/test.html">Default Host</a>
</body>
</html>
/etc/apache2/sites-available/iw.linuxhotel.de : ( Debian 5 - 7 ) apache Version 2.2
<VirtualHost *:80>
ServerName iw.linuxhotel.de
DocumentRoot /srv/iw.linuxhotel.de/html
<Directory "/srv/iw.linuxhotel.de/html">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/iw.linuxhotel.de.conf : ( Debian 8 ) apache Version 2.4
<VirtualHost *:80>
ServerName iw.linuxhotel.de
DocumentRoot /srv/iw.linuxhotel.de/html
<Directory "/srv/iw.linuxhotel.de/html">
Require all granted
</Directory>
</VirtualHost>
mkdir -p /srv/iw.linuxhotel.de/{html,cgi-bin}
a2ensite iw.linuxhotel.de
apache2ctl configtest
/srv/iw.linuxhotel.de/html/index.html : ( Debian 5.0 )
<html>
<head>
<title>Virtual Host iw!</title>
</head>
<body>
Virtual Host iw<br/>
<a href="http://notebook34.linuxhotel.de/test.html">Default Host</a>
</body>
</html>
Debian, openSuSE, Ubuntu:
apache2ctl -S
Centos:
httpd -S
/etc/init.d/apache2 restart
oder Configtest und Reload in einem: graceful
SuSE 10.2, Debian 4.0:
apache2ctl graceful
Centos 5:
apachectl graceful
netcat -v localhost 80 GET /test.html http/1.1 host: iw.linuxhotel.de
wget -nv -O - --header="Host: iw.linuxhotel.de" http://localhost/test.html
ab -H 'Host: iw.linuxhotel.de' http://localhost/test.html