Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
|
lpi2:apache-virtual-hosts [2016/03/18 11:33] ingo_wichmann [Debian] |
lpi2:apache-virtual-hosts [2024/04/25 13:41] (aktuell) |
||
|---|---|---|---|
| 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 bis 12.3 ) | + | ==== HTML-Dateien ablegen ==== |
| + | openSuSE ab 10.2: | ||
| + | <file html /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> | ||
| + | </file> | ||
| - | <file> | + | mkdir -p /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs} |
| - | NameVirtualHost * | + | |
| + | openSuSE ab 10.2: | ||
| + | <file html /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> | ||
| </file> | </file> | ||
| - | ''/etc/apache2/conf.d/default_vhost.conf'' : ( SuSE ab 10.2 ) | + | ==== Apache Konfiguration ==== |
| + | openSuSE bis 12.3: | ||
| + | <file txt /etc/apache2/listen.conf> | ||
| + | NameVirtualHost * | ||
| + | </file> | ||
| - | <file> | + | openSuSE ab 10.2: |
| + | <file txt /etc/apache2/conf.d/default_vhost.conf> | ||
| <VirtualHost *> | <VirtualHost *> | ||
| </VirtualHost> | </VirtualHost> | ||
| </file> | </file> | ||
| - | ''/etc/apache2/vhosts.d/iw.linuxhotel.de.conf'' : ( SuSE ab 10.2 ) | + | openSuSE ab 42.1: |
| - | + | <file txt /etc/apache2/vhosts.d/iw.linuxhotel.de.conf> | |
| - | <file> | + | |
| <VirtualHost *> | <VirtualHost *> | ||
| ServerName iw.linuxhotel.de | ServerName iw.linuxhotel.de | ||
| Zeile 32: | Zeile 57: | ||
| <Directory "/srv/www/iw.linuxhotel.de/htdocs"> | <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 ==== |
| apache2ctl configtest | apache2ctl configtest | ||
| + | Vhosts anzeigen: | ||
| apache2ctl -S | apache2ctl -S | ||
| + | ==== Konfiguration neu laden ==== | ||
| + | apache2ctl graceful | ||
| + | |||
| + | ===== CentOS 7 ===== | ||
| ==== HTML-Dateien ablegen ==== | ==== HTML-Dateien ablegen ==== | ||
| - | ''/srv/www/htdocs/test.html'' : ( SuSE ab 10.2 ) | + | <file html /var/www/html/test.html> |
| - | + | ||
| - | <file> | + | |
| <html> | <html> | ||
| <head> | <head> | ||
| Zeile 51: | Zeile 78: | ||
| </head> | </head> | ||
| <body> | <body> | ||
| - | Default Host notebook34<br/> | + | <h1>Default Host notebook34</h1> |
| <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a> | <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a> | ||
| </body> | </body> | ||
| Zeile 57: | Zeile 84: | ||
| </file> | </file> | ||
| - | mkdir -p /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs} | + | mkdir -p /var/www/iw.linuxhotel.de/{cgi-bin,html} |
| - | + | ||
| - | ''/srv/www/iw.linuxhotel.de/htdocs/test.html'' : ( SuSE ab 10.2 ) | + | |
| - | <file> | + | <file html /var/www/iw.linuxhotel.de/html/test.html> |
| <html> | <html> | ||
| <head> | <head> | ||
| Zeile 73: | Zeile 98: | ||
| </file> | </file> | ||
| - | ===== CentOS 5 ===== | + | ==== Apache Konfiguration ==== |
| - | ''/etc/httpd/conf/httpd.conf'': ( Centos 5 ) | + | <file txt /etc/httpd/conf.d/vhosts.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 * | + | |
| <VirtualHost *:80> | <VirtualHost *:80> | ||
| </VirtualHost> | </VirtualHost> | ||
| Zeile 96: | Zeile 106: | ||
| </file> | </file> | ||
| - | mkdir vhosts.d | + | mkdir /etc/httpd/vhosts.d |
| - | + | ||
| - | ''/etc/httpd/vhosts.d/iw.linuxhotel.de.conf'' : ( Centos 5 ) | + | |
| - | <file> | + | <file txt /etc/httpd/vhosts.d/iw.linuxhotel.de.conf> |
| <VirtualHost *:80> | <VirtualHost *:80> | ||
| ServerName iw.linuxhotel.de | ServerName iw.linuxhotel.de | ||
| Zeile 106: | 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> | ||
| - | ==== Configdateien überprüfen ==== | + | ==== Konfigdateien überprüfen ==== |
| apachectl configtest | apachectl configtest | ||
| - | apachectl -S | + | Vhosts anzeigen: |
| + | httpd -S | ||
| - | ==== HTML-Dateien ablegen ==== | + | ==== Konfiguration neu laden ==== |
| - | ''/var/www/html/test.html'' : ( Centos 5 ) | + | apachectl graceful |
| - | <file> | + | ===== Debian / Ubuntu ===== |
| + | ==== HTML-Dateien ablegen ==== | ||
| + | <file html /var/www/html/test.html> | ||
| <html> | <html> | ||
| <head> | <head> | ||
| Zeile 125: | Zeile 135: | ||
| </head> | </head> | ||
| <body> | <body> | ||
| - | Default Host notebook34<br/> | + | <h1>Default Host notebook34</h1> |
| - | <a href="http://iw.linuxhotel.de/test.html">Virtual Host</a> | + | Link zu <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 /srv/iw.linuxhotel.de/{html,cgi-bin} |
| - | + | Debian (ab 8): | |
| - | ''/var/www/iw.linuxhotel.de/html/test.html'' : ( Centos 5 ) | + | <file html /srv/iw.linuxhotel.de/html/test.html> |
| - | + | ||
| - | <file> | + | |
| <html> | <html> | ||
| <head> | <head> | ||
| Zeile 141: | Zeile 149: | ||
| </head> | </head> | ||
| <body> | <body> | ||
| - | Virtual Host iw<br/> | + | <h1>Virtual Host iw</h1> |
| - | <a href="http://notebook34.linuxhotel.de/test.html">Default Host</a> | + | Link zu <a href="http://notebook34.linuxhotel.de/test.html">Default Host</a> |
| </body> | </body> | ||
| </html> | </html> | ||
| </file> | </file> | ||
| - | ===== Debian / Ubuntu ===== | + | ==== Apache Konfiguration ==== |
| - | + | Debian (ab 8), Ubuntu (ab 16.04): | |
| - | ''/etc/apache2/sites-available/iw.linuxhotel.de'' : ( Debian 5 - 7 ) //apache Version 2.2// | + | <file txt /etc/apache2/sites-available/iw.linuxhotel.de.conf> |
| - | <file> | + | |
| - | <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> | + | |
| - | </file> | + | |
| - | + | ||
| - | ''/etc/apache2/sites-available/iw.linuxhotel.de.conf'' : ( Debian 8 ) //apache Version 2.4// | + | |
| - | <file> | + | |
| <VirtualHost *:80> | <VirtualHost *:80> | ||
| ServerName iw.linuxhotel.de | ServerName iw.linuxhotel.de | ||
| Zeile 173: | Zeile 167: | ||
| </VirtualHost> | </VirtualHost> | ||
| </file> | </file> | ||
| - | mkdir -p /srv/iw.linuxhotel.de/{html,cgi-bin} | ||
| a2ensite iw.linuxhotel.de | a2ensite iw.linuxhotel.de | ||
| - | ==== Configdateien überprüfen ==== | + | ==== Konfigdateien überprüfen ==== |
| apache2ctl configtest | apache2ctl configtest | ||
| - | + | Vhosts anzeigen: | |
| - | ==== HTML-Dateien ablegen ==== | + | |
| - | + | ||
| - | ''/srv/iw.linuxhotel.de/html/index.html'' : ( Debian 5.0 ) | + | |
| - | + | ||
| - | <file> | + | |
| - | <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> | + | |
| - | </file> | + | |
| - | + | ||
| - | ===== Testen ===== | + | |
| - | ==== vhost-Konfiguration überprüfen ==== | + | |
| - | + | ||
| - | Debian, openSuSE: | + | |
| 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 -v localhost 80 | + | |
| - | GET /test.html http/1.1 | + | |
| host: iw.linuxhotel.de | host: iw.linuxhotel.de | ||