Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


fortgeschrittene:apache

Dies ist eine alte Version des Dokuments!


Apache Out of the Box

Benötigte Pakete

Fedora:

httpd

SuSE:

apache2 apache2-prefork

Debian ab 3.1:

apache2 apache2-mpm-prefork

Konfiguration

Im einfachsten Fall

  • startet man den Webserver
  • hinterlegt eine Webseite
  • und greift darauf zu

/var/www/html/test.html: ( CentOS )

/srv/www/htdocs/test.html: ( SuSE 10.0 )

/var/www/index.html : ( Debian 5.0 )

<html>
  <head>
    <title>Hello World!</title>
  </head>
  <body>
    Hello World
  </body>
</html>

Testen

telnet localhost 80
GET http://localhost/test.html HTTP/1.1
Host: localhost

Namebased Virtual Hosts

Vorraussetzung: 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 10.2 )

NameVirtualHost *

/etc/apache2/conf.d/default_vhost.conf : ( SuSE 10.2 )

<VirtualHost *>
</VirtualHost>

/etc/apache2/vhosts.d/iw.linuxhotel.de.conf : ( SuSE 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 -t

HTML-Dateien ablegen

/srv/www/htdocs/test.html : ( SuSE 10.2 )

<html>
  <head>
    <title>Default Host notebook34!</title>
  </head>
  <body>
    Default Host notebook34
  </body>
</html>
mkdir /srv/www/iw.linuxhotel.de/{cgi-bin,htdocs}

/srv/www/iw.linuxhotel.de/htdocs/test.html : ( SuSE 10.2 )

<html>
  <head>
    <title>Virtual Host iw!</title>
  </head>
  <body>
    Virtual Host iw
  </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
  </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
  </body>
</html>

Debian (5.0)

/etc/apache2/sites-enabled/000-default : ( Debian 5.0 )

<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>
mkdir -p /var/www/notebook32.linuxhotel.de/html

/etc/apache2/sites-available/iw.linuxhotel.de : ( Debian 5.0 )

<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>
mkdir -p /var/www/iw.linuxhotel.de/{html,cgi-bin}
a2ensite iw.linuxhotel.de

Configdateien überprüfen

apache2ctl configtest

HTML-Dateien ablegen

/var/www/notebook32.linuxhotel.de/html/index.html : ( Debian 5.0 )

<html>
  <head>
    <title>Default Host notebook32!</title>
  </head>
  <body>
    Default Host notebook32
  </body>
</html>

/var/www/iw.linuxhotel.de/html/index.html : ( Debian 5.0 )

<html>
  <head>
    <title>Virtual Host iw!</title>
  </head>
  <body>
    Virtual Host iw
  </body>
</html>

Testen

vhost-Konfiguration überprüfen:

Debian:

apache2ctl -S

SuSE, 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:

telnet localhost 80
GET /test.html http/1.1
host: iw.linuxhotel.de

IPv6 abschalten

/etc/apache2/ports.conf : ( Debian 4.0 )

Listen 0.0.0.0:80

Dokumentation

fortgeschrittene/apache.1290778475.txt.gz · Zuletzt geändert: 2011/04/07 07:25 (Externe Bearbeitung)