Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


lpi2:apache-virtual-hosts

Namebased Virtual Hosts

Vorraussetzung: apache, bind und dns

Namen im DNS eintragen

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

Namensauflösung testen

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

SuSE

HTML-Dateien ablegen

openSuSE ab 10.2:

/srv/www/htdocs/test.html
<html>
  <head>
    <title>Default Host notebook34!</title>
  </head>
  <body>
    <h1>Default Host notebook34</h1>
    Link zu <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a>
  </body>
</html>
mkdir -p /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs}

openSuSE ab 10.2:

/srv/www/iw.linuxhotel.de/htdocs/test.html
<html>
  <head>
    <title>Virtual Host iw!</title>
  </head>
  <body>
    <h1>Virtual Host iw</h1>
    Link zu <a href="http://notebook34.linuxhotel.de/test.html">Default Host</a>
  </body>
</html>

Apache Konfiguration

openSuSE bis 12.3:

/etc/apache2/listen.conf
NameVirtualHost *

openSuSE ab 10.2:

/etc/apache2/conf.d/default_vhost.conf
<VirtualHost *>
</VirtualHost>

openSuSE ab 42.1:

/etc/apache2/vhosts.d/iw.linuxhotel.de.conf
<VirtualHost *>
  ServerName iw.linuxhotel.de
  DocumentRoot /srv/www/iw.linuxhotel.de/htdocs
 
  <Directory "/srv/www/iw.linuxhotel.de/htdocs">
    Require all granted
  </Directory>
</VirtualHost>

Konfigdateien überprüfen

apache2ctl configtest

Vhosts anzeigen:

apache2ctl -S

Konfiguration neu laden

apache2ctl graceful

CentOS 7

HTML-Dateien ablegen

/var/www/html/test.html
<html>
  <head>
    <title>Default Host notebook34!</title>
  </head>
  <body>
    <h1>Default Host notebook34</h1>
    <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a>
  </body>
</html>
mkdir -p /var/www/iw.linuxhotel.de/{cgi-bin,html}
/var/www/iw.linuxhotel.de/html/test.html
<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>

Apache Konfiguration

/etc/httpd/conf.d/vhosts.conf
<VirtualHost *:80>
</VirtualHost>
 
Include vhosts.d/*.conf
mkdir /etc/httpd/vhosts.d
/etc/httpd/vhosts.d/iw.linuxhotel.de.conf
<VirtualHost *:80>
  ServerName iw.linuxhotel.de
  DocumentRoot /var/www/iw.linuxhotel.de/html
 
  <Directory "/var/www/iw.linuxhotel.de/html">
    Require all granted
  </Directory>
</VirtualHost>

Konfigdateien überprüfen

apachectl configtest

Vhosts anzeigen:

httpd -S

Konfiguration neu laden

apachectl graceful

Debian / Ubuntu

HTML-Dateien ablegen

/var/www/html/test.html
<html>
  <head>
    <title>Default Host notebook34!</title>
  </head>
  <body>
    <h1>Default Host notebook34</h1>
    Link zu <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a>
  </body>
</html>
mkdir -p /srv/iw.linuxhotel.de/{html,cgi-bin}

ab Debian 5.0:

/srv/iw.linuxhotel.de/html/test.html
<html>
  <head>
    <title>Virtual Host iw!</title>
  </head>
  <body>
    <h1>Virtual Host iw</h1>
    Link zu <a href="http://notebook34.linuxhotel.de/test.html">Default Host</a>
  </body>
</html>

Apache Konfiguration

Debian 5 - 7: apache Version 2.2

/etc/apache2/sites-available/iw.linuxhotel.de
<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>

Debian ab 8, Ubuntu 16.04: apache Version 2.4

/etc/apache2/sites-available/iw.linuxhotel.de.conf
<VirtualHost *:80>
  ServerName iw.linuxhotel.de
  DocumentRoot /srv/iw.linuxhotel.de/html
 
  <Directory "/srv/iw.linuxhotel.de/html">
    Require all granted
  </Directory>
</VirtualHost>
a2ensite iw.linuxhotel.de

Konfigdateien überprüfen

apache2ctl configtest

Vhosts anzeigen:

apache2ctl -S

Konfiguration neu laden

apache2ctl graceful

Virtual-Host testen

netcat

1)

netcat -Cv 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
1)
-C habe ich zum ersten Mal unter Debian 8 gebraucht
lpi2/apache-virtual-hosts.txt · Zuletzt geändert: 2021/11/28 19:18 von arne_wichmann