Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
lpi2:apache-virtual-hosts [2015/06/11 10:34] 127.0.0.1 Externe Bearbeitung |
lpi2:apache-virtual-hosts [2024/04/25 13:41] |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== 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 ) | ||
- | |||
- | <file> | ||
- | NameVirtualHost * | ||
- | </file> | ||
- | |||
- | ''/etc/apache2/conf.d/default_vhost.conf'' : ( SuSE ab 10.2 ) | ||
- | |||
- | <file> | ||
- | <VirtualHost *> | ||
- | </VirtualHost> | ||
- | </file> | ||
- | |||
- | ''/etc/apache2/vhosts.d/iw.linuxhotel.de.conf'' : ( SuSE ab 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 -S | ||
- | |||
- | ==== HTML-Dateien ablegen ==== | ||
- | ''/srv/www/htdocs/test.html'' : ( SuSE ab 10.2 ) | ||
- | |||
- | <file> | ||
- | <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> | ||
- | </file> | ||
- | |||
- | mkdir -p /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs} | ||
- | |||
- | ''/srv/www/iw.linuxhotel.de/htdocs/test.html'' : ( SuSE ab 10.2 ) | ||
- | |||
- | <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> | ||
- | |||
- | ===== CentOS 5 ===== | ||
- | ''/etc/httpd/conf/httpd.conf'': ( Centos 5 ) | ||
- | |||
- | <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> | ||
- | |||
- | Include vhosts.d/*.conf | ||
- | </file> | ||
- | |||
- | mkdir vhosts.d | ||
- | |||
- | ''/etc/httpd/vhosts.d/iw.linuxhotel.de.conf'' : ( Centos 5 ) | ||
- | |||
- | <file> | ||
- | <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> | ||
- | </file> | ||
- | |||
- | ==== Configdateien überprüfen ==== | ||
- | apachectl configtest | ||
- | apachectl -S | ||
- | |||
- | ==== HTML-Dateien ablegen ==== | ||
- | ''/var/www/html/test.html'' : ( Centos 5 ) | ||
- | |||
- | <file> | ||
- | <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> | ||
- | </file> | ||
- | |||
- | mkdir /var/www/iw.linuxhotel.de/{cgi-bin,html} | ||
- | |||
- | ''/var/www/iw.linuxhotel.de/html/test.html'' : ( Centos 5 ) | ||
- | |||
- | <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> | ||
- | |||
- | ===== Debian ===== | ||
- | |||
- | ''/etc/apache2/sites-available/iw.linuxhotel.de'' : ( Debian 5 - 7 ) //apache Version 2.2// | ||
- | <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> | ||
- | ServerName iw.linuxhotel.de | ||
- | DocumentRoot /srv/iw.linuxhotel.de/html | ||
- | |||
- | <Directory "/srv/iw.linuxhotel.de/html"> | ||
- | Require all granted | ||
- | </Directory> | ||
- | </VirtualHost> | ||
- | </file> | ||
- | 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 ) | ||
- | |||
- | <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 | ||
- | |||
- | 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 | ||
- | |||