Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


fortgeschrittene:apache-virtual-hosts

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
fortgeschrittene:apache-virtual-hosts [2011/09/29 07:25]
ingo_wichmann [vhost-Konfiguration überprüfen]
fortgeschrittene:apache-virtual-hosts [2024/04/25 13:41] (aktuell)
sh [HTML-Dateien ablegen]
Zeile 1: Zeile 1:
 ====== Namebased Virtual Hosts ====== ====== Namebased Virtual Hosts ======
 Vorraussetzung:​ [[apache]], [[bind]] und [[dns]] Vorraussetzung:​ [[apache]], [[bind]] und [[dns]]
- 
-Achtung: in der Apache-Konfiguration ist die Reihenfolge wichtig. ​ 
  
 ===== Namen im DNS eintragen ===== ===== Namen im DNS eintragen =====
-Die Namen aller Virtual Hosts müssen ​im DNS eingetragen ​sein, fehlende wie unter [[bind]] gezeigt hinzufügen+Die Namen aller Virtual Hosts sind im DNS eingetragen,​ fehlende wie unter [[bind]] gezeigt hinzufügen
 ==== Namensauflösung testen ==== ==== Namensauflösung testen ====
   getent hosts notebook14.linuxhotel.de   getent hosts notebook14.linuxhotel.de
Zeile 11: Zeile 9:
  
 ===== SuSE ===== ===== SuSE =====
-''/​etc/​apache2/​listen.conf''​ : ( SuSE 10.2 ) 
- 
-<​file>​ 
-NameVirtualHost * 
-</​file>​ 
- 
-''/​etc/​apache2/​conf.d/​default_vhost.conf''​ : ( SuSE 10.2 ) 
- 
-<​file>​ 
-<​VirtualHost *> 
-</​VirtualHost>​ 
-</​file>​ 
- 
-''/​etc/​apache2/​vhosts.d/​iw.linuxhotel.de.conf''​ : ( SuSE 10.2 ) 
- 
-<​file>​ 
-<​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>​ 
-</​file>​ 
- 
-==== Configdateien überprüfen ==== 
-  apache2ctl configtest 
-  apache2ctl -t 
- 
 ==== HTML-Dateien ablegen ==== ==== HTML-Dateien ablegen ====
-''​/​srv/​www/​htdocs/​test.html''​ : ( SuSE 10.2 ) +openSuSE ab 10.2: 
- +<file html /​srv/​www/​htdocs/​test.html>​
-<file>+
 <​html>​ <​html>​
   <​head>​   <​head>​
Zeile 51: Zeile 17:
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Default Host notebook34+    ​<h1>Default Host notebook34</​h1>​ 
 +    Link zu <a href="​http://​iw.linuxhotel.de/​test.html">​Virtual Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
-  mkdir /​srv/​www/​iw.linuxhotel.de/​{cgi-bin,​htdocs}+  mkdir -p /​srv/​www/​iw.linuxhotel.de/​{cgi-bin,​htdocs}
  
-''​/​srv/​www/​iw.linuxhotel.de/​htdocs/​test.html''​ : ( SuSE 10.2 ) +openSuSE ab 10.2: 
- +<file html /​srv/​www/​iw.linuxhotel.de/​htdocs/​test.html>​
-<file>+
 <​html>​ <​html>​
   <​head>​   <​head>​
Zeile 66: Zeile 32:
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Virtual Host iw+    ​<h1>Virtual Host iw</​h1>​ 
 +    Link zu <a href="​http://​notebook34.linuxhotel.de/​test.html">​Default Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
-===== CentOS 5 ===== +==== Apache Konfiguration ​==== 
-''/​etc/​httpd/​conf/​httpd.conf''​( Centos 5 ) +openSuSE bis 12.3
- +<​file ​txt /etc/apache2/listen.conf>
-<file+
-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 * NameVirtualHost *
 +</​file>​
  
-<​VirtualHost *:80>+openSuSE ab 10.2: 
 +<file txt /​etc/​apache2/​conf.d/​default_vhost.conf>​ 
 +<​VirtualHost *>
 </​VirtualHost>​ </​VirtualHost>​
- 
-Include vhosts.d/​*.conf 
 </​file>​ </​file>​
  
-  mkdir vhosts.d +openSuSE ab 42.1: 
- +<file txt /etc/apache2/​vhosts.d/​iw.linuxhotel.de.conf>​ 
-''​/etc/httpd/​vhosts.d/​iw.linuxhotel.de.conf''​ : ( Centos 5 ) +<​VirtualHost *>
- +
-<file+
-<​VirtualHost *:80>+
   ServerName iw.linuxhotel.de   ServerName iw.linuxhotel.de
-  DocumentRoot /var/​www/​iw.linuxhotel.de/​html+  DocumentRoot /srv/​www/​iw.linuxhotel.de/​htdocs
  
-  <​Directory "/var/​www/​iw.linuxhotel.de/​html">​ +  <​Directory "/srv/​www/​iw.linuxhotel.de/​htdocs">​ 
-    ​Order allow,​deny +    ​Require ​all granted
-    Allow from all+
   </​Directory>​   </​Directory>​
 </​VirtualHost>​ </​VirtualHost>​
 </​file>​ </​file>​
  
-==== Configdateien ​überprüfen ==== +==== Konfigdateien ​überprüfen ==== 
-  ​apachectl ​configtest +  ​apache2ctl ​configtest 
-  ​apachectl ​-S+Vhosts anzeigen: 
 +  ​apache2ctl ​-S 
 + 
 +==== Konfiguration neu laden ==== 
 +  apache2ctl graceful
  
 +===== CentOS 7 =====
 ==== HTML-Dateien ablegen ==== ==== HTML-Dateien ablegen ====
-''​/​var/​www/​html/​test.html''​ : ( Centos 5 ) +<file html /​var/​www/​html/​test.html>​
- +
-<file>+
 <​html>​ <​html>​
   <​head>​   <​head>​
Zeile 123: Zeile 78:
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Default Host notebook34+    ​<h1>Default Host notebook34</​h1>​ 
 +    <a href="​http://​iw.linuxhotel.de/​test.html">​Virtual Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
-  mkdir /​var/​www/​iw.linuxhotel.de/​{cgi-bin,​html} +  mkdir -p /​var/​www/​iw.linuxhotel.de/​{cgi-bin,​html}
- +
-''/​var/​www/​iw.linuxhotel.de/​html/​test.html''​ : ( Centos 5 )+
  
-<​file>​+<​file ​html /​var/​www/​iw.linuxhotel.de/​html/​test.html>
 <​html>​ <​html>​
   <​head>​   <​head>​
Zeile 138: Zeile 92:
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Virtual Host iw+    Virtual Host iw<​br/>​ 
 +    <a href="​http://​notebook34.linuxhotel.de/​test.html">​Default Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
- +==== Apache Konfiguration ​==== 
- +<file txt /etc/httpd/conf.d/vhosts.conf>
-===== Debian (5.0) ===== +
-''​/etc/apache2/sites-enabled/000-default''​ : ( Debian 5.0 ) +
- +
-<file>+
 <​VirtualHost *:80> <​VirtualHost *:80>
-        ServerAdmin webmaster@notebook32.linuxhotel.de 
-        DocumentRoot /​var/​www/​notebook32.linuxhotel.de/​html 
- 
-        <​Directory /​var/​www/​notebook32.linuxhotel.de/​html>​ 
-                Order allow,deny 
-                allow from all 
-        </​Directory>​ 
- 
-        ErrorLog /​var/​log/​apache2/​error.log 
-        CustomLog /​var/​log/​apache2/​access.log combined 
 </​VirtualHost>​ </​VirtualHost>​
  
 +Include vhosts.d/​*.conf
 </​file>​ </​file>​
  
-  mkdir -p /var/www/notebook32.linuxhotel.de/​html+  mkdir /etc/httpd/vhosts.d
  
-''​/etc/apache2/sites-available/​iw.linuxhotel.de''​ : ( Debian 5.0 ) +<file txt /etc/httpd/vhosts.d/​iw.linuxhotel.de.conf>
-<file>+
 <​VirtualHost *:80> <​VirtualHost *:80>
   ServerName iw.linuxhotel.de   ServerName iw.linuxhotel.de
Zeile 173: Zeile 114:
  
   <​Directory "/​var/​www/​iw.linuxhotel.de/​html">​   <​Directory "/​var/​www/​iw.linuxhotel.de/​html">​
-    ​Order allow,​deny +    ​Require ​all granted
-    Allow from all+
   </​Directory>​   </​Directory>​
 </​VirtualHost>​ </​VirtualHost>​
 </​file>​ </​file>​
  
-  mkdir -p /​var/​www/​iw.linuxhotel.de/​{html,​cgi-bin} +==== Konfigdateien überprüfen ==== 
-  ​a2ensite iw.linuxhotel.de+  ​apachectl configtest 
 +Vhosts anzeigen: 
 +  httpd -S
  
-==== Configdateien überprüfen ​==== +==== Konfiguration neu laden ==== 
-  ​apache2ctl configtest+  ​apachectl graceful
  
 +===== Debian / Ubuntu =====
 ==== HTML-Dateien ablegen ==== ==== HTML-Dateien ablegen ====
- +<file html /​var/​www/​html/​test.html>
-''​/var/www/​notebook32.linuxhotel.de/html/index.html''​ : ( Debian 5.0 ) +
- +
-<file>+
 <​html>​ <​html>​
   <​head>​   <​head>​
-    <​title>​Default Host notebook32!</​title>​+    <​title>​Default Host notebook34!</​title>​
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Default Host notebook32+    ​<h1>Default Host notebook34</​h1>​ 
 +    Link zu <a href="​http://​iw.linuxhotel.de/​test.html">​Virtual Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
-''​/var/www/​iw.linuxhotel.de/​html/​index.html''​ : ( Debian ​5.0 ) +  mkdir -p /srv/​iw.linuxhotel.de/​{html,cgi-bin} 
- +Debian ​(ab 8): 
-<​file>​+<​file ​html /​srv/​iw.linuxhotel.de/​html/​test.html>
 <​html>​ <​html>​
   <​head>​   <​head>​
Zeile 208: Zeile 149:
   </​head>​   </​head>​
   <​body>​   <​body>​
-    Virtual Host iw+    ​<h1>Virtual Host iw</​h1>​ 
 +    Link zu <a href="​http://​notebook34.linuxhotel.de/​test.html">​Default Host</​a>​
   </​body>​   </​body>​
 </​html>​ </​html>​
 </​file>​ </​file>​
  
-===== Testen ===== +==== Apache Konfiguration ​==== 
-==== vhost-Konfiguration überprüfen ====+Debian (ab 8), Ubuntu (ab 16.04): 
 +<file txt /​etc/​apache2/​sites-available/​iw.linuxhotel.de.conf>​ 
 +<​VirtualHost *:80> 
 +  ServerName iw.linuxhotel.de 
 +  DocumentRoot /​srv/​iw.linuxhotel.de/​html
  
-Debian, openSuSE:+  <​Directory "/​srv/​iw.linuxhotel.de/​html">​ 
 +    Require all granted 
 +  </​Directory>​ 
 +</​VirtualHost>​ 
 +</​file>​ 
 +  a2ensite iw.linuxhotel.de 
 + 
 +==== Konfigdateien überprüfen ==== 
 +  apache2ctl configtest 
 +Vhosts anzeigen:
   apache2ctl -S   apache2ctl -S
  
-Centos: +==== Konfiguration ​neu laden ====
-  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   apache2ctl graceful
  
-Centos 5: +===== Virtual-Host testen ​===== 
-  apachectl graceful +=== netcat === 
- +(( ''​-C''​ habe ich zum ersten Mal unter Debian 8 gebraucht )) 
-==== Virtual-Host testen ==== +  netcat ​-Cv localhost 80 
-=== netcat ​/ telnet ​=== +  GET /​test.html ​HTTP/1.1
-  netcat localhost 80 +
-  GET /​test.html ​http/1.1+
   host: iw.linuxhotel.de   host: iw.linuxhotel.de
  
 === wget === === wget ===
-  wget -O - --header="​Host:​ iw.linuxhotel.de"​ http://​localhost+  wget -nv -O - --header="​Host:​ iw.linuxhotel.de"​ http://​localhost/test.html
  
 === ab === === ab ===
-  ab -H 'Host: iw.linuxhotel.de'​ http://​localhost/​+  ab -H 'Host: iw.linuxhotel.de'​ http://​localhost/​test.html 
  
fortgeschrittene/apache-virtual-hosts.1317281129.txt.gz · Zuletzt geändert: 2011/09/29 07:25 von ingo_wichmann