Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


No renderer 'pdf' found for mode 'pdf'
lpi2:apache-virtual-hosts

Dies ist eine alte Version des Dokuments!


Namebased Virtual Hosts

Vorraussetzung: apache, bind und dns

Achtung: in der Apache-Konfiguration ist die Reihenfolge wichtig.

Namen im DNS eintragen

Die Namen aller Virtual Hosts müssen im DNS eingetragen sein, fehlende wie unter bind gezeigt hinzufügen

Namensauflösung testen

getent hosts notebook14.linuxhotel.de
getent hosts iw.linuxhotel.de

SuSE

/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>

Configdateien überprüfen

apache2ctl configtest
apache2ctl -S

HTML-Dateien ablegen

/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>

CentOS 5

/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>

Configdateien überprüfen

apachectl configtest
apachectl -S

HTML-Dateien ablegen

/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>

Debian

/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

Configdateien überprüfen

apache2ctl configtest

HTML-Dateien ablegen

/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>

Testen

vhost-Konfiguration überprüfen

Debian, openSuSE:

apache2ctl -S

Centos:

httpd -S

Apache neu starten

/etc/init.d/apache2 restart

oder Configtest und Reload in einem: graceful

SuSE 10.2, Debian 4.0:

apache2ctl graceful

Centos 5:

apachectl graceful

Virtual-Host testen

netcat / telnet

netcat -v localhost 80
GET /test.html http/1.1
host: iw.linuxhotel.de

wget

wget -nv -O - --header="Host: iw.linuxhotel.de" http://localhost/test.html

ab

ab -H 'Host: iw.linuxhotel.de' http://localhost/test.html
lpi2/apache-virtual-hosts.1434018867.txt.gz · Zuletzt geändert: 2016/03/18 11:33 (Externe Bearbeitung)