Apache: Difference between revisions
| Line 116: | Line 116: | ||
==Logging== | ==Logging== | ||
If you have done a default installation of Apache, when you run your server, two log files will get written. These files are called access_log (access.log on Windows) and error_log (error.log on Windows). These files can be found | If you have done a default installation of Apache, when you run your server, two log files will get written. These files are called access_log (access.log on Windows) and error_log (error.log on Windows). | ||
These files can be found: | |||
* Ubuntu: in /var/log/apache2/logs. | |||
* Windows: will be in the logs subdirectory of wherever you installed Apache. | |||
Es kann konfiguriert werden, was im Access-Log geloggt wird. Ein Standard-Auszug zeigen folgende Zeilen: | Es kann konfiguriert werden, was im Access-Log geloggt wird. Ein Standard-Auszug zeigen folgende Zeilen: | ||
123.45.678.90 - - 07/Mar/2000:14:27:12 -0800 | |||
123.45.678.90 - - 07/Mar/2000:14:27:12 -0800 | "GET /mypage.html HTTP/1.1" 200 10369 | ||
"GET /mypage.html HTTP/1.1" 200 10369 | |||
<RemoteHostIPAdress> <Identity> <Authentification> <TimeOfTheRequest> '''"'''<Method> <Resource> <Protocol>'''"''' <StatusCode> <BytesTransferedToClient> | <RemoteHostIPAdress> <Identity> <Authentification> <TimeOfTheRequest> '''"'''<Method> <Resource> <Protocol>'''"''' <StatusCode> <BytesTransferedToClient> | ||
| Line 139: | Line 140: | ||
In einem Skript-Log können CGI-Skript Aufrufe protokolliert werden. | In einem Skript-Log können CGI-Skript Aufrufe protokolliert werden. | ||
==Version== | ==Version== | ||
Die genutzte Version findet man am einfachsten über: | Die genutzte Version findet man am einfachsten über: | ||
phpinfo(). | phpinfo(). | ||
Revision as of 20:13, 27 February 2012
Download
can be downloaded from here
Konfiguration
Konfiguration steht in httpd.conf, bei einigen Distributionen auch apache2.conf genannt, unter Windows im Verzeichnis <ApacheInstallationDir>\conf\ und unter Linux unter etc/httpd/ oder /etc/apache2/. A describition of the apache2 directory structure and configuration can be found here.
A test can be made by calling
<APACHE_INSTALL_DIR>\bin\Apache -t
The file contains directives and containers, which enable you to customize your Apache installation. Directives configure specific settings of Apache, such as authorization, performance, and network parameters. Containers specify the context to which those settings refer. For example, authorization configuration can refer to the server as a whole, to a directory, or to a single file. Containers, also called sections, limit the scope for which directives apply. If directives are not inside a container, they belong to the default server scope (server config) and apply to the server as a whole.
These are the default Apache directive containers:
<VirtualHost>
A VirtualHost directive specifies a virtual server. Apache enables you to host different websites with a single Apache installation. Directives inside this container apply to a particular website. This directive accepts a domain name or IP address and an optional port as arguments. You will learn more about virtual hosts in Chapter 29, "Apache Performance Tuning and Virtual Hosting."
<Directory>, <DirectoryMatch>
These containers allow directives to apply to a certain directory or group of directories in the file system. Directory containers take a directory or directory pattern argument. Enclosed directives apply to the specified directories and their subdirectories. The DirectoryMatch container allows regular expression patterns to be specified as an argument. For example, the following allows a match of all second-level subdirectories of the www directory that are made up of four numbers, such as a directory named after a year and month (0906 for September 2006):
<DirectoryMatch "^/www/.*/0-9{4}"> AllowOverride steuert, ob .htaccess die Einstellungen übersteuern können
<Location>, <LocationMatch>
These containers allow directives to apply to certain requested URLs or URL patterns. They are similar to their Directory counterparts. LocationMatch takes a regular expression as an argument. For example, the following matches directories containing either "/my/data" or "/your/data":
<LocationMatch "/(my|your)/data">
<Files>, <FilesMatch>
Similar to Directory and Location containers, Files sections allow directives to apply to certain files or file patterns.
Zugriffsschutz
Apache has three distinct ways of dealing with the question of whether a particular request for a resource will result in that resource actually be returned. These criteria are called Authorization, Authentication, and Access control. Authentication is any process by which you verify that someone is who they claim they are. This usually involves a username and a password, but can include any other method of demonstrating identity, such as a smart card, retina scan, voice recognition, or fingerprints. Authentication is equivalent to showing your drivers license at the ticket counter at the airport. Authorization is finding out if the person, once identified, is permitted to have the resource. This is usually determined by finding out if that person is a part of a particular group, if that person has paid admission, or has a particular level of security clearance. Authorization is equivalent to checking the guest list at an exclusive party, or checking for your ticket when you go to the opera. Finally, access control is a much more general way of talking about controlling access to a web resource. Access can be granted or denied based on a wide variety of criteria, such as the network address of the client, the time of day, the phase of the moon, or the browser which the visitor is using. Access control is analogous to locking the gate at closing time, or only letting people onto the ride who are more than 48 inches tall - it's controlling entrance by some arbitrary condition which may or may not have anything to do with the attributes of the particular visitor.
Die weitaus häufigste Umsetzung des Zugriffsschutz basiert auf den Dateien .htaccess (Standardname, der per Apache-Einstellung geändert werden kann) und .htpasswd basierende Passwortschutz. An .htaccess file is simply a text file containing Apache directives. Those directives apply to the documents in the directory where the .htaccess file is located, and to all subdirectories under it as well. Other .htaccess files in subdirectories may change or nullify the effects of those in parent directories. Die Einstellungen, die in der Datei .htaccess vorgenommen werden müssen, lassen sich ebenso in den Apache-Konfigurationsdateien httpd.conf oder access.conf bewerkstelligen. Der Weg per .htaccess reichlich in der Literatur und im Web dokumentiert ist, die Methode per httpd.conf ist einfach und komfortabel. Damit .htaccess funktioniert muss AllowOverride in http.conf entsprechend gesetzt sein. Die Einrichtung des Schutzes passiert nach folgendem Prinzip: in einer Datei (.htaccess, access.conf, oder httpd.conf), die normalerweise wird das Verzeichnis angegeben, das geschützt werden soll sowie der Pfad der Passwort-Datei. In der wiederum stehen die Usernamen und deren verschlüsselte Passwörter. Im Folgenden wird als Dateiname .passwort gewählt. Mit dem (unter Linux und anderen Unixen) standardmäßig installierten Programm htpasswd wird die Passwort-Datei erzeugt und editiert (vorher als root anmelden):
htpasswd -c <Pfad>/.passwort tux htpasswd <Pfad>/.passwort geeko
Im ersten Schritt wird die Datei erzeugt (-c für create) und der Benutzer Tux angelegt. Im zweiten der Benutzer Geeko hinzugefügt. Jedes mal wird man nach Eingabe eines Passwortes mit anschließender Wiederholung gefragt. Zu beachten ist, daß der Pfad der Passwortdatei über dem Document root-Pfad liegt, damit die Datei von außen nicht erreichbar ist. Die Verschlüsselung (durch die Unix-Funktion crypt()) ist zwar sicher. Trotzdem soll der User ja auch nicht die Zugangsnamen der berechtigten User sehen, die unverschlüsselt in der Datei auftauchen. Die Datei .passwort sieht nämlich jetzt ungefähr so aus:
tux:nxvWrU1S95NnU geeko:nxvWrU1S95NnU
Anschießend wird die Datei /etc/httpd/httpd.conf, die Konfigurationsdatei für den Apache-Server, editiert und der Apache anschließend neu gestartet (beides als root). Möglicherweise sind Zugangsanweisungen auch in der Datei /etc/httpd/access.conf eingetragen. Dann sollte man die Änderungen dort vornehmen. Im folgenden wird davon ausgegangen, dass die komplette Apache-Konfiguration in httpd.conf realisiert ist. Falls schon Verzeichnisse geschützt sind, schreibe man günstigerweise die neuen Anweisungen in die Nähe der schon bestehenden. Dazu suche man nach dem String "<Directory". Folgender Abschnitt ist dann einzufügen:
# hier steht das Verzeichnis, das samt den Dokumenten geschützt werden soll <Directory /usr/local/httpd/htdocs/myhomepage/vip> # frei wählbarer Name des Bereiches, der bei der Anmeldung angezeigt wird AuthName "VIPs region" # die Art der Identifizierung, i.d.R. "Basic" eintragen AuthType Basic # der Pfad der Passwort-Datei, hier im gleichen Verzeichnis wie httpd.conf AuthUserFile /etc/httpd/.passwort # die Zugangsberechtigten require user geeko tux </Directory>
Möglich ist auch die Angabe require valid-user, wodurch alle in der Passwort-Datei aufgelisteten User zugangsberechtigt sind. Danach muß der Apache neu gestartet werden.
Zusätzlich besteht die Möglichkeit, eine ganze Gruppe zu definieren. Dazu muß eine Gruppen-Datei angelegt werden, die wiederum in der httpd.conf festgelegt wird. Dann kommen folgende Zeilen hinzu (bzw. kann dann auch die Zeile mit AuthUserFile... wegfallen):
AuthGroupFile /etc/httpd/.group require group vips
Die Datei .group hat dann folgenden Inhalt:
vips: tux geeko
Die Passwort-Datei mus im gleichen Verzeichnis stehen wie die Gruppen-Datei. Die Dateien .passwort und .group müssen für alle lesbar sein, also müssen folgende Rechte gesetzt werden:
chmod 644 .passwort chmod 644 .group
Zwei weitere Möglichkeiten des Zugriffsschutzes bestehen noch: Der limitierte Zugriff für bestimmte hosts, die in der httpd.conf definiert werden müssen und YP-basierter Zugriffsschutz.
Operations
Ubuntu
cd /etc/init.d ./apache [start|stop|restart]
Modules
On windows systems the modules are located in <APACHE_INSTALL_DIR>\modules\ and have the extensions *.so or *.dll.
Apache Webserver und Application Server (Tomcat, JBoss)
Um bestimmte Aufrufe an ein Web-Application Server wie Jakarta Tomcat weiter zu routen, müssen folgende Einträge in httpd.conf gemacht bzw. auskommentiert werden:
#begin 4 tomcat configuration
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass /uweheuer http://localhost:8088/uweheuer
ProxyPassReverse /uweheuer http://localhost:8088/uweheuer
#end 4 tomcat configuration
Der Apache HTTP-Server fungiert somit als Proxy.
Dateiablage
Windows
Die Dateien müssen unter <INSTALL_DIRECTORY>\htdocs\ liegen. Falls kein spezieller Dateiname in der URL angegeben ist wird index.html verwendet.
Ubuntu
\var\www\
Logging
If you have done a default installation of Apache, when you run your server, two log files will get written. These files are called access_log (access.log on Windows) and error_log (error.log on Windows). These files can be found:
- Ubuntu: in /var/log/apache2/logs.
- Windows: will be in the logs subdirectory of wherever you installed Apache.
Es kann konfiguriert werden, was im Access-Log geloggt wird. Ein Standard-Auszug zeigen folgende Zeilen:
123.45.678.90 - - 07/Mar/2000:14:27:12 -0800 "GET /mypage.html HTTP/1.1" 200 10369
<RemoteHostIPAdress> <Identity> <Authentification> <TimeOfTheRequest> "<Method> <Resource> <Protocol>" <StatusCode> <BytesTransferedToClient>
Statt der <RemoteHostIPAdress> kann auch über der HostNameLookups-Direktive der tatsächliche Hostname protokolliert werden, was allerdings Einfluß auf die Performance hat. <Identity> ist heutzutage in der Regel leer, also -. <Authenfication> ist in der Regel nicht erforderlich, daher auch in der Regel -.
Zusätzlich gibt es noch ein Error-Log, das ebenfalls konfiguriert werden kann. Ein Standard-Auszug zeigen folgende Zeilen: [Tue Mar 07 09:59:29 2000] [error] client 123.45.678.90 File does not exist: /path/to/htdocs/nonexistent.html [Tue Mar 07 09:52:40 2000] notice SIGHUP received. Attempting to restart [Tue Mar 07 09:52:42 2000] notice Apache/1.3.11 (Unix) configured
-- resuming normal operations
In einem Skript-Log können CGI-Skript Aufrufe protokolliert werden.
Version
Die genutzte Version findet man am einfachsten über:
phpinfo().