Apache Webserver


Der Apache Webserver ist einer der ersten Webserver, entwickelt von der NCSA (National Center for Supercomputing Applications) an der University of Illinois. Der Apache Webserver dient zur Darstellung von Internetseiten.

Die Apache Foundation hat dann die Enticklung von Apache2 übernommen. Der Dienst „apache2“ oder „httpd“, setzt sich aus verschiedenen Paketen z.B dem Webserver, Bibliotheken, Plugins, Programmiersprachen etc. zusammen. Seit Version 2 gibt es Multi-Threading verfahren wie apache 2 mit Anfragen verfährt (per-child, prefork, worker).








Der Webserver „apache2“ kann entweder direkt aus den Quellen der Apache Foundation heruntergeladen und installiert werden oder die Paketquellen der Linux Distributionen genutzt werden.



Aus den Quellen der Apache Foundation installieren




Für die Installation aus den Apache Quellen werden weitere Werkzeuge zur Kompilierung benötigt wie z.B. „make“, „build-essential“, „gcc“, „g++“, usw.




Zuerst wird ein Installationsverzeichnis in z.B. „/usr/src/“ erstellt.

root@home:# mkdir /usr/src/apache2.4




In das Installationsverzeichnis wechseln und „apache2“ Quellpakete heunterladen und entpacken.

root@home:/usr/src/apache2.4# wget http://ftp.fau.de/apache//httpd/httpd-2.4.9.tar.bz2


root@home:/usr/src/apache2.4# tar -xvjf httpd-2.4.9.tar.bz2




Jetzt werden die Programme zur Kompilierung (make, build-essential, gcc, g++, usw.) benötigt.


Hierzu in das Verzeichnis „/usr/src/apache2.4/httpd-2.4.9/“ wechseln.

root@home:/usr/src/apache2.4/httpd-2.4.9# ./configure --prefix=/usr/local/apache2 --enable-http --enable-https --enable-so --enable-cgi

Hier muß das Installationsverzeichnis mit [--prefix] angegeben werden, die Option [--enable] aktiviert verschiedene Apache2 Funktionen.


Eine Komplette Liste der Konfigurations Optionen erhält man, in dem man im Quellverzeichnis „./configure --help“ ausführt.




Nach der Konfiguration kann der Apache2 Webserver kompiliert und installiert werden.

root@home:/usr/src/apache2.4/httpd-2.4.9# make



root@home:/usr/src/apache2.4/httpd-2.4.9# make install




Nach der Installation kann der Webserver gestartet werden.

root@home:# /usr/local/apache2/bin/apachectl start
Starting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
.

Weitere Optionen sind [stop], [restart], [reload] (liest die Konfigurationsdatei neu ein).


Gibt der Apache Webserver beim Start folgende Meldung aus („Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName“), kann man in der Datei „/usr/local/apache2/conf/httpd.conf“ die Zeile „ServerName debian.home.net:80“ eintragen.





Aus den Quellen der Linux Distributionen installieren


Bei Debian Systemen kann man den Apache2 Webserver wie folgt installieren.


root@home:# apt-get install apache2




Möchte man PHP, CGI, MySQL und andere Funktionen nutzen, sind die gewünschten Module mit/nach zu installieren.

root@home:~# apt-get install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-cli php5-cgi libapache2-mod-fcgid php-pear php-auth php5-mcrypt mcrypt php5-imagick imagemagick libruby libapache2-mod-ruby




Bei RedHat Systemen gibt es folgendes Kommando:

[root@hostname ~]# yum install httpd





Apache2 Installation testen


Nachdem der Webserver gestartet wurde, kann er in einem Browser mit „http://serverip-oder-name“ getestet werden.



Browser Ausgabe einer Apache 2.2 installation auf einem Debian System.




Browser Ausgabe einer Apache 2.4 installation auf einem Debian System.






Apache2.2 Konfigurationsdateien
debian SuSE
Datei Beschreibung Datei Beschreibung
/etc/apache2/apache2.conf Hauptkonfigurationsdatei /etc/apache2/httpd.conf Konfigurationsdateien
/etc/apache2/httpd.conf Benutzerspezifische Konfiguration /etc/apache2/*.conf globale Konfiguration
/etc/apache2/ports.conf überwachte Ports /etc/apache2/sysconf.d/*.conf automatisch generierte Konfiguration
/etc/apache2/mods-enable/*.load Erweiterungsmodule /etc/apache2/conf.d/*.conf sonstige Konfiguration
/etc/apache2/mods-enable/*.conf Erweiterungsmodule Konfig. /etc/apache2/vhosts.d/*.conf Virtuelle Hosts
/etc/apache2/conf.d/ Konfigurationsdateien /srv/www/ root Webverzeichnis
/etc/apache2/sites-enabled/ Virtuelle Hosts /srv/www/htdocs Document root
/var/www/ root Webverzeichnis /srv/www/cgi-bin CGI Binaries
/etc/init.d/apache2 Start - Stop /usr/sbin/apache2ctl Start - Stop
/etc/rc.d/apache2 Runtime Script /etc/rc.d/apache2 Runtime Script
/var/log/apache2/access_log Logdatei für Zugriffe /var/log/apache2/access_log Logdatei für Zugriffe
/var/log/apache2/error_log Logdatei für Error Zugriffe /var/log/apache2/error_log Logdatei für Error Zugriffe
/var/log/apache2/ssl_access_log Log für SSL Zugriffe /var/log/apache2/ssl_access_log Log für SSL Zugriffe
/var/log/apache2/ssl_error_log Log für SSL Error Zugriffe /var/log/apache2/ssl_error_log Log für SSL Error Zugriffe
/var/log/apache2/ssl_requests_log Log für Verbindungsversuche /var/log/apache2/ssl_requests_log Log für Verbindungsversuche




Red Hat apache2
Datei Beschreibung Datei Beschreibung
/etc/httpd/conf/httpd.conf Hauptkonfigurationsdatei /usr/local/apache2/conf/httpd.conf Hauptkonfigurationsdatei



FIXME




Nach dem Start lauscht der Webserver in den Standardeinstellungen auf Port 80. Die Dateien befinden sich im Webverzeichnis Dokument Root. Bei Debian z.B. in „/var/www“, seit Debian 8 Jessie und apache 2.4 in „/var/www/html“. Das Hauptwebverzeichnis kann auch angepasst werden, z.B. auf „/srv/www“.



Debian Apache Start / Stop

/etc/init.d/apache2 start|stop|restart|reload|restart|force-reload

Debian mit init-V System.


service apache2 start|stop|restart|reload|restart|force-reload

Debian mit Systemd Prozessverwaltung.


  • restart ⇒ startet Apache neu.
  • reload ⇒ lädt Konfigurationsdateien neu.
  • restart ⇒ startet Apache neu.
  • force-reload ⇒ lädt Konfigurationsdateien neu, wenn dabei Verbindungen getrennt werden müssen.




Bei Installationen aus den Debian Quellen, startet der Apache Webserver bei Systemstart automatisch mit. Folgender Befehl entfernt den Apache aus der Autostartliste, so dass der Webserver manuell gestartet werden muß:

update-rc.d -f apache2 remove

Bei init-V Systemen.


systemctl disable apache2

Mit Systemd.



SuSE Apache Start / Stop

apache2ctl start|stop|rcvars|configtest|restart




  • rcvars ⇒ lädt Konfigurationsdateien neu.
  • configtest ⇒ prüft Konfigurationsdatei.
  • restart ⇒ startet Apache neu.





RedHat Apache Start / Stop

httpd start|stop|rcvars|configtest|restart


… oder automatisch beim Systemstart mit dem RC Skript in „/usr/sbin/apachectl“.




Die Konfigurationsdateien befinden sich je nach Distribution in „/etc/apache2/“ oder „/etc/httpd/“. Bei einer Installation aus den Apache Quellen befinden sich die Konfigurationsdateien in „/usr/local/apache2/conf/httpd.conf“. „/usr/local“ ist das Installationsverzeichnis.


Ab Apache 2.4 wurden einige Änderungen in der Konfiguration durchgeführt. Das ist zu beachten, wenn ein Update von einer Apache 2.2 Installation durchgeführt wurde oder Dateien aus anderen Systemen migriert wurden.




Konfigurationsdateien einer apache2.4 Installation aus den Debian Quellen.

root@home:/etc/apache2# tree
.
├── apache2.conf
├── conf-available
│   ├── charset.conf
│   ├── javascript-common.conf
│   ├── localized-error-pages.conf
│   ├── other-vhosts-access-log.conf
│   ├── phpmyadmin.conf -> ../../phpmyadmin/apache.conf
│   ├── security.conf
│   └── serve-cgi-bin.conf
├── conf-enabled
│   ├── charset.conf -> ../conf-available/charset.conf
│   ├── localized-error-pages.conf -> ../conf-available/localized-error-pages.conf
│   ├── other-vhosts-access-log.conf -> ../conf-available/other-vhosts-access-log.conf
│   ├── phpmyadmin.conf -> ../conf-available/phpmyadmin.conf
│   ├── security.conf -> ../conf-available/security.conf
│   └── serve-cgi-bin.conf -> ../conf-available/serve-cgi-bin.conf
├── envvars
├── magic
├── mods-available
│   ├── access_compat.load
│   ├── actions.conf
│   ├── ...
│   ├── ...
│   ├── ...
│   ├── userdir.conf
│   ├── userdir.load
│   ├── usertrack.load
│   ├── vhost_alias.load
│   └── xml2enc.load
├── mods-enabled
│   ├── access_compat.load -> ../mods-available/access_compat.load
│   ├── alias.conf -> ../mods-available/alias.conf
│   ├── alias.load -> ../mods-available/alias.load
│   ├── auth_basic.load -> ../mods-available/auth_basic.load
│   ├── ...
│   ├── ...
│   ├── ...
│   ├── php7.0.conf -> ../mods-available/php7.0.conf
│   ├── php7.0.load -> ../mods-available/php7.0.load
│   ├── reqtimeout.conf -> ../mods-available/reqtimeout.conf
│   ├── reqtimeout.load -> ../mods-available/reqtimeout.load
│   ├── setenvif.conf -> ../mods-available/setenvif.conf
│   ├── setenvif.load -> ../mods-available/setenvif.load
│   ├── status.conf -> ../mods-available/status.conf
│   └── status.load -> ../mods-available/status.load
├── ports.conf
├── sites-available
│   ├── 000-default.conf
│   └── default-ssl.conf
└── sites-enabled
    └── 000-default.conf -> ../sites-available/000-default.conf


  • apache2.conf ⇒ Hauptkonfigurationsdatei.
  • conf-available ⇒ Verzeichnis für weitere, verfügbare VirtualHost Dateien wie z.B. „phpmyadmin“.
  • conf-enabled ⇒ Werden weitere VirtualHosts aktiviert (a2enconf (Name des VHosts)), erstellt das Kommando automatisch einen Symlink.
  • mods-available ⇒ In diesem Verzeichnis befinden sich verfügbare Module.
  • mods-enabled ⇒ Aktivierte Module.
  • ports.conf ⇒ Auf welchen Port lauscht der Webserver.
  • sites-available ⇒ Verzeichnis für eigene VHosts, die im Webverzeichnis liegen, das in der Datei „/etc/apache2.conf“ festgelegt wurde.
  • sites-enabled ⇒ Via Symlink aktivierte VirtualHosts.





Apache Konfiguration überprüfen




root@home:/etc/apache2# apache2ctl configtest
Syntax OK




Zum suchen von Schlüsselwörter kann man auch wie folgt vorgehen:

cd /etc/apache2
find -type f -exec grep -i -q [Schlüsselwort] ^; -print





apache2.conf


Die Datei „/etc/apache2/apache2.conf“ ist bei Debian Systemen die Hauptkonfigurations- und Globale Einstellungsdatei des Apache Webservers.

Je nach Distribution werden alle Einstellungen in dieser Datei oder verteilt auf mehreren Dateien, (z.B. ports.conf, httpd.conf …) vorgenommen.



Beispiel einer /etc/apache2/apache2.conf Datei aus einer apache 2.4 Installation auf einem Debian System.

Anzeigen

Ausblenden

# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#	/etc/apache2/
#	|-- apache2.conf
#	|	`--  ports.conf
#	|-- mods-enabled
#	|	|-- *.load
#	|	`-- *.conf
#	|-- conf-enabled
#	|	`-- *.conf
# 	`-- sites-enabled
#	 	`-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

#<Directory /var/www/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>

#<Directory /var/cache/munin/www/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>

<Directory /srv/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf




Beispiel einer /etc/apache2/apache2.conf Datei aus einer apache 2.2 Installation auf einem Debian System.

Anzeigen

Ausblenden

#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "foo.log"
# with ServerRoot set to "/etc/apache2" will be interpreted by the
# server as "/etc/apache2/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
## 

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/




Mit der Direktive „UserDir“ kann man ein Verzeichnis im Homeverzeichnis eines Nutzers angeben, in dem dieser seine Dateien über Apache2 veröffentlichen kann.





Optionen:

  • DocumentRoot ⇒ Verzeichnis in dem Apache die Webseiten erwartet.
  • Timeout ⇒ Zeit bis zum Timeout für Anfrage einer Seite.
  • MaxClients ⇒ Anzahl der Clients die Apache gleichzeitig bedient. Default 150.
  • LoadModule ⇒ Welche Module sollen geladen werden.
  • Port ⇒ der Port, auf dem Apache auf Anfragen wartet.
  • Directory ⇒ Hier werden Zugriffs und andere Rechte für ein Verzeichnis vergeben.
  • DirectoryIndex ⇒ Einstellungen nach welchen Dateien Apache sucht um eine URL zu vervollständigen bei der die Angabe der Datei Fehlt. Default ist „index.html“.
  • AllowOverride ⇒ Einstellen ob die lokalen Dateien die globalen Einstellungen überschreiben können. Mögliche Werte sind None, All und in Kombination mit Options, FileInfo, AuthConfig und Limit. z.B. für .htaccess Dateien. Diese Einstellung gilt rekursiv auf alle Unterverzeichnisse.
  • Order ⇒ Zeigt an, in welcher Reihenfolge die Zugriffsrechte angewandt werden.
  • AccessFileName ⇒ Name der Datei mit der die globalen Einstellungen überschrieben werden können. Default .htaccess.
  • ErrorLog ⇒ Zeigt den Namen der Datei, in der Apache Fehlermeldungen ausgibt.
  • LogLevel ⇒ Diese Einstellung zeigt, in welcher Dringlichkeitsstufe die Meldungen ausgegeben werden. Default warn.
  • Alias ⇒ Gibt ein Shortcut auf ein Verzeichnis an.
  • ScriptAlias ⇒ Zeigt an, dass Dateien als CGI Script behandelt werden sollen.
  • Server Side Includes ⇒können aktiviert werden, indem man alle Dateien nach SSIs untersuchen lässt.





httpd.conf


Unter SuSE , RedHat Systeme ist die Datei „httpd.conf“, die Hauptkonfigurationsdatei des Apache Webservers. (Konfiguration ähnlich wie „apache2.conf“).



ports.conf


In der „ports.conf“ Datei ist festgelegt, auf welchem Port der Webserver lauschen soll.


  • ports.conf ⇒ bei Debian Systemen.
  • listen.conf ⇒ SuSE.




root@home:/etc/apache2# cat ports.conf 
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
</IfModule>




Wenn keine IP Adresse vor dem gelisteten Port steht bindet sich der Webserver an alle verfügbaren IP Adressen des Systems. Der Apache kann an eine oder mehrere Adressen in einer Liste gebunden werden, gibt man an der Stelle listen 127.0.0.1:80 ein, lässt sich der Webserver nur noch lokal ansprechen.




Listen 192.168.178.65:80
# oder mehrzeilig
Listen 192.168.178.65:80
Listen 127.0.0.0:8000
...





DocumentRoot


Als DocumentRoot wird das Auslieferungsverzeichnis des Webservers bezeichnet. Hier werden der Ort des Verzeichnisses oder Aliase für weitere Web Applikationen konfiguriert.

Möchte man einen neuen VirtualHost im Webverzeichnis anlegen, z.B. unter „/srv/www/internetauftritt1/index.html“, muss dieser Ort dem Webserver bekanntgegeben und aktiviert werden.


Hier ist zwischen Apache 2.2 und Apache 2.4 Installationen zu unterscheiden, da sich die Optionen und Bezeichnung der VirtualHost Dateien geändert haben.




root@home:/etc/apache2/sites-enabled# ll
insgesamt 0
lrwxrwxrwx 1 root root 35 Mär 31 19:07 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root 35 Mär 31 19:07 internetauftritt1.conf -> ../sites-available/internetauftritt1.conf

Apache 2.4.


root@home:/etc/apache2/sites-enabled# ll
insgesamt 0
lrwxrwxrwx 1 root root 26 16. Jan 2015  000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 30 16. Jan 2015  internetauftritt1 -> ../sites-available/internetauftritt1

Apache 2.2



Die Konfigurationsdatei „default“, „000-default.conf“ bei Debian oder „default.server.conf“ bei SuSE Systeme verweist in den Standardeinstellungen auf die Startseite des Apache2 Webservers.


Beispiel einer Standard 000-default.conf auf einem Debian System:

root@home:/etc/apache2/sites-enabled# cat 000-default.conf 
<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /srv/www/html

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>




Soll ein neuer VirtualHost angelegt werden, kann als Muster die Datei „000-default.conf“ kopiert und danach angepasst werden.

root@home:/etc/apache2/sites-available#cp 000-default.conf internetauftritt1.conf




FIXME



Die Zugriffssteuerung auf Webverzeichnisse befindet sich im <Directory> Abschnitt.


Ein Beispiel: In Zeile 16 (Auskommentiert) kann ein „alias“ eingerichtet werden. Dieser verweist dann beim Aufruf von „localhost/seite3“ sofort auf das Verzeichnis „/srv/www/verzeichnis/seite3“.

  1<VirtualHost *:80>
  2         ServerAdmin webmaster@localhost
  3         # Basisverzeichnis des Webservers
  4         DocumentRoot /srv/www/
  5         <Directory />
  6                 Options FollowSymLinks
  7                 AllowOverride None
  8         </Directory>
  9         <Directory /srv/www/>
 10                 Options Indexes FollowSymLinks MultiViews    # folgt Sybolischen Links, zum Abstellen...#Options None
 11                 AllowOverride None    # .htaccess oder .htdocs hat keine Wirkung
 12                 Order deny,allow    # welche Regel zuerst angewendet werden soll
 13                 allow from all    # Zugriff für alle erlauben
 14         </Directory>                                                                                    #allow from 192.168.0.0/8 # lokalem Netz 
 15         # Aliase für cgi scripte                                                                        #allow from .[domain] # aus lokalem Netz
 16         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/     #Alias /seite3 /srv/www/verzeichnis/seite3          #allow from localhost # localhost
 17         <Directory "/usr/lib/cgi-bin">
 18                 AllowOverride None
 19                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
 20                 Order allow,deny
 21                 Allow from all
 22         </Directory>
 23 
 24         ErrorLog /var/log/apache2/error.log
 25 
 26         # Possible values include: debug, info, notice, warn, error, crit,
 27         # alert, emerg.
 28         LogLevel warn
 29 
 30         CustomLog /var/log/apache2/access.log combined
 31 
 32     Alias /doc/ "/usr/share/doc/"
 33     <Directory "/usr/share/doc/">
 34         Options Indexes MultiViews FollowSymLinks
 35         AllowOverride None
 36         Order deny,allow
 37         Deny from all
 38         Allow from 127.0.0.0/255.0.0.0 ::1/128
 39     </Directory>
 40 
 41 </VirtualHost>

Beispiel: debian /etc/apache2/sites-available/default.


Bei Änderungen an den Apache Konfigurationsdateien ist ein Neustart des Webservers notwendig!





Alias


Um Webverzeichnisse auch außerhalb des DocumentRoot zu binden, kann im Verzeichnis „/etc/apache2/sites-available/“, in der jeweiligen Konfigurationsdatei ein Alias eingerichtet werden.


# Ergänzung zu /etc/apache2/sites-available/default
Alias /help/ "/daten/hilfedateien/"
Alias /help "/daten/hilfedateien/" 
<Directory "/daten/hilfedateien/"> 
    # Abweichende Optionen von
    # der Directory
</Directory>

In diesem Beispiel können die Hilfeseiten mit „/help“ direkt aufgerufen werden.



sysconf.d (SuSE)


Bei SuSE werden alle .conf Dateien im Verzeichnis „sysconf.d“ abgelegt. Bei jedem Apache Neustart durch das „init V Skript neu erstellt. Zum Einbinden von Modulen und Seiten werden dabei in der Datei “/etc/sysconfig/apache2„ die Variablen angepasst bzw. hinzugefügt (APACHE_MODULES, APACHE_CONF_INCLUDE_FILE).



Benutzerbezogener Zugriff


Sollte man benutzerbezogenen Zugriff auf dem Webserver gewähren wollen, kann hierfür das Verzeichnis “~/public_html„ angelegt werden, dieses wird automatisch von Apache eingebunden und ist dann unter „localhost/~username/“ bzw. “<server-ip>/~username/„ erreichbar.


Zuerst muß noch das Modul [mod_userdir] mit folgenden Befehl aktiviert werden:

sudo a2enmod userdir

Danach sollte der Webserver neugestartet bzw. die Konfigurationsdateien neu eingelesen werden.


Das Verzeichnis “~/public_html„ und “/home/<username>/„ benötigt dabei die Rechte 755, Dateien im „public_html“ Verzeichnis meistens 644. Dabei ist zu beachten dass der Server in der Gruppe „www-data“ (Debian) ist und dieser auf das Verzeichnis lese bzw. schreibrechte hat. Soll ein Nutzer schreibrechte erhalten, muß er der Gruppe „www-data“ hinzugefügt werden.




Wenn auf einem Mehrbenutzersystem einem Nutzer Schreibrechte auf das „www“ Verzeichnis gegeben werden soll, kann man das Verzeichnis einer Gruppe X mit den jeweiligen Schreibrechten hinzufügen. Der Apache läuft unter der Gruppe „www-data“, sollte dabei ein Sicherheitsloch im Webserver ausgenutzt werden, so hat der Angreifer keine Schreibrechte im „www“ Verzeichnis.





Passwortschutz


Um einen Passwortschutz auf ein Webverzeichnis anzulegen, wechseln Sie in das Verzeichnis in der Passwortdatei gespeichert werden soll, das Passwort dann mit dem Befehl „htpasswd2“ anlegen. Apache benötigt hierfür Leserechte auf die Passwortdatei und dem Verzeichnis.


htpasswd2 -c passwords.pwd username




Damit Apache die Passwortdatei berücksichtigt, gibt es die Option über die Datei “/etc/apache2/sites-available/<VirtualHost Datei>„ (Debian) oder „httpd.conf“ (SuSE), dieses Verzeichnis mit einem Passwort zu schützen.

# Dieses Verzeichnis Passwortschützen
<Directory "/srv/www/seite1/admin/">
    AuthType Basic
    AuthUserFile /pfad zum verzeichnis/passwords.pwd
    AuthName "admin"                                   # Gültigkeitsbereich des Users admin
    Require valid-user    # weitere Option Require user name1 name2
    # ...
</Directory>




Der Passwortschutz eines Webverzeichnisses ist auch über eine “.htaccess„ Datei möglich. Hier müssen die gleichen Anweisungen stehen, wie in der VirtualHost Datei:

# Zugriff von Überall erlauben
order deny,allow
allow from all
deny from



# Zugriff nur vom lokalen Netzwerk erlauben
order deny,allow
deny from all
allow from 192.168.178




Diese Datei wird vom Webserver nur berücksichtigt wenn die Option AllowOverride oder AllowOverride All in /etc/apache2/sites-available/<VirtualHost Datei> aktiviert ist.




Beispiele:



Beispiel: Direktive hinzufügen, zum schützen von Dateien in /daten.

<Directory /srv/www/daten>
    AuthName "Daten"
    AuthType Basic
    AuthUserFile /etc/apache2/pwords    # Diese Datei muß noch angelegt werden (Beispiel unten)
        <Limit GET>
        order deny,allow
        require valid-user    # Mindestens ein Valid User wird benötigt
        </Limit>
</Directory>




Danach wird die Passwort Datei erstellt:

htpasswd2 -c /etc/apache2/pwords <benutzernamen>

Die Option [-c] (Create) wird nur beim erstellen benötigt. Es können dabei belibig viele Benutzer und Gruppen definiert werden.


<Directory /srv/www/daten>
    AuthName "Daten"
    AuthType Basic
    AuthUserFile /etc/apache2/pwords
    AuthGroupFile /etc/apache2/pgroups
        <Limit GET>
        order deny,allow
        require group daten
        </Limit>
</Directory>




Die referenzierte Datei AuthGroupFile wird mit folgenden Text angelegt:

# Gruppenname: user1 user2 ....
daten: <benutzername>




Beispiel: Hinzufügen eines ErrorDocument.

<Directory /srv/www/daten>
    AuthName "Daten"
    AuthType Basic
    AuthUserFile /etc/apache2/pwords
    AuthGroupFile /etc/apache2/pgroups
    ErrorDocument 401 "Du hast keinen Zugriff, bitte Admin kontaktieren"
        <Limit GET>
        order deny,allow
        require group daten
        </Limit>
</Directory>




Beispiel: Aussperren von Subnetz 192.168.0.0.

<Directory /srv/www/daten>
    AuthName "Daten"
    AuthType Basic
    AuthUserFile /etc/apache2/pwords
    AuthGroupFile /etc/apache2/pgroups
        <Limit GET>
        order allow from all            # erlauben ist möglich ... # Deny from all
        deny from 192.168.0.0/255.255.0.0                          # Allow from <domain>.de
        require group daten                                        # Falls der Server <domain>.de nicht Auflösen kann
        </Limit>                                                   # kann man den Servernamen in die /etc/hosts eintragen
</Directory>





VirtualHost


Mit VirtualHosts ist es möglich, mehrere Domains mit einem Webserver zu betreiben. Das http/1.1 Protokoll wurde entwickelt um beim Zugriff auf eine Seite den Hostnamen mitzusenden. Der Server kann unter einer IP Adresse verschiedene Domains verschiedener Webseiten ausliefern. Unter Apache ist hierfür VirtualHost zuständig.


Dabei wird zwischen mehreren Konzepten unterschieden:

  • Namensbasierte Virtuelle Hosts ⇒ Mehr als ein Angebot pro IP
  • IP basierte Viruelle Hosts ⇒ Eine IP pro Angebot
  • Mehrere Instanzen von Apache auf einem Rechner laufen lassen.



Es kann dazu das Konfigurationstemplate kopiert und editiert werden.



Namensbasierte Virual Hosts


Namensbasierte Virtuelle Hosts werden für eine gemeinsame IP Adresse aufgelöst. Im Verzeichnis “/etc/apache2/sites-available„ kann die Datei *default* als Vorlage genommen werden. Für jeden virtuellen Host sollte eine eigene Datei angelegt werden.


<VirtualHost *>
    ServerName www.<domain>.de
    DocumentRoot /srv/www/unterverzeichnis/www.<domain>.de
    ...
    # Optional
    ServerAdmin webmaster@<domain>.de
    ErrorLog /var/log/apache2/www.<domain>.de-error_log
    CustomLog /var/log/apache2/www.<domain>.de-access_log common
    ...
<VirtualHost>




Die VirtualHost Direktive kann statt * auf eine IP begrenzt werden.




Je nach System muß dann noch in der Datei „ports.conf“, der VirtualHost Name eingetragen werden.

NameVirtualHost *





IP basierte Virtual Hosts


Mit IP bsierten Virtual Hosts kann man außer auf der ursprünglichen IP noch weitere Domains mit zusätzlichen IPs hosten. Hierfür muß man auf dem System mehrere IPs einrichten. Die Instanz von Apache bedient mehrere Domains, wobei jeder Domain eine IP zugewiesen ist.


  • IP Alias einrichten.




Dass Apache mehrere IPs hosten kann muß das System mehrere IPs aktzeptieren (Multi-IP-Hosting).




Beispiel: Weitere IPs hinzufügen (als root).

ifconfig eth0:0 192.168.1.41
ifconfig eth0:1 192.168.1.42



… oder

<VirtualHost 192.168.1.41>
    ServerName www.<anderedomain>.de
    DocumentRoot /srv/www/www.<domain>.de
    # Optional
    ServerAdmin webmaster@<anderedomain>.de
    ErrorLog /var/log/apache2/www.<anderedomain>.de-error_log
    CustomLog /var/log/apache2/www.<anderedomain>.de-access_log common
<VirtualHost>



<VirtualHost 192.168.1.42>
    ServerName www.<nocheinedomain>.de
    DocumentRoot /srv/www/www.<nocheinedomain>.de
    # Optional
    ServerAdmin webmaster@<nocheinedomain>.de
    ErrorLog /var/log/apache2/www.<nocheinedomain>.de-error_log
    CustomLog /var/log/apache2/www.<nocheinedomain>.de-access_log common
<VirtualHost>


Hier werden die VirtualHost Direktiven nur für zusätzliche Domains angegeben, die ursprüngliche Domain www.<domain>.de wird immer noch über die Einstellungen DocumentRoot usw. außerhalb der VirtualHost Blöcke konfiguriert.


Das Verzeichnis muß angelegt sein und „www-data“ gehören. Wenn der Server unter dieser IP oder Namen noch nicht erreichbar ist sollte die Datei “/etc/hosts„ mit dem Client-PC ergänzt werden. Unter Windows findet man diese Datei unter „c:\windows\system32\drivers\etc\hosts“.




Möchte man einen VirtualHost nur von einer bestimmten IP (Range) oder nur aus dem Lokalen Netzwerk, kann folgender Eintrag in das Dokument Root Direktory, der VirtualHost Datei vorgenommen werden.



Alias /phpmyadmin /srv/www/phpmyadmin
...
<Directory /srv/www/phpmyadmin>
        Order deny,allow
        Deny from ALL
        Allow from localhost 127.0.0.0/8 ::1
        Allow from 192.168.178
        Options None
...
...
</Directory> 


In obigen Beispiel wird der Aufruf von phpmyadmin nur noch aus dem Lokalen Netz erlaubt.



Virtuelle Hosts aktivieren / deaktivieren


sites-available / sites-enabled


Mit diesem Modul werden VirtuellHosts aktiviert, dabei befinden sich die Konfigurationsdateien in „sites-available“ und die Links in „sites-enabled.


cd /etc/apache2/sites-available/
# Aktivieren
a2ensite <virthostdatei>
# Deaktivieren
a2dissite <virthostdatei>



Beim aktivieren wird ein symbolischer Link für den VirtualHost im Verzeichnis “/etc/apache2/sites-enabled“ erzeugt. Dieser kann auch manuell mit ln -s erzeugt werden.

Beispiel bis Apache Version 2.2.x:

Die aktiven VirtualHost's werden als symbolische Links im Verzeichnis „/etc/apache2/sites-enabled“ angezeigt.

root@home:/etc/apache2/sites-enabled# ll
insgesamt 0
lrwxrwxrwx 1 root root 26 Jan 24  2015 ampache -> ../sites-available/ampache
lrwxrwxrwx 1 root root 29 Apr  2  2015 linux-wiki -> ../sites-available/linux-wiki
lrwxrwxrwx 1 root root 37 Mai 11  2016 site3 -> ../sites-available/site3
lrwxrwxrwx 1 root root 34 Mai 11  2016 site4 -> ../sites-available/site4
lrwxrwxrwx 1 root root 28 Mai 23  2015 site5 -> ../sites-available/site5




Die verfügbaren VirtualHost's werden als Dateien im Verzeichnis „/etc/apache2/sites-available“ aufgeführt.

root@home:/etc/apache2/sites-available# ll
insgesamt 32
-rw-r--r-- 1 root root  851 Jan 24  2015 ampache
-rw-r--r-- 1 root root  706 Jan 24  2015 default
-rw-r--r-- 1 root root 7251 Dez 22  2014 default-ssl
-rw-r--r-- 1 root root  934 Apr  2  2015 linux-wiki
-rw-r--r-- 1 root root  948 Mai 11  2016 site3
-rw-r--r-- 1 root root  933 Mai 11  2016 site4
-rw-r--r-- 1 root root  806 Mai 23  2015 site5




Die Datei „ampache“ als Beispiel betrachtet:

Anzeigen

Ausblenden

<VirtualHost *:80>
        #ServerAdmin webmaster@localhost
        ServerName ampache.home.org
        ServerAlias ampache.home.org *.ampache.home.org
        DocumentRoot /srv/www/ampache
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /srv/www/ampache/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                #Order allow,deny
                Order deny,allow
                #allow from all
                Deny from All
                Allow from 192.168.178
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>




Weitere symbolische Links zu VirtualHost's befinden sich im Verzeichnis „/etc/apache2/conf.d“

root@home:/etc/apache2/conf.d# ll
insgesamt 20
-rw-r--r-- 1 root root  237 Dez 23  2014 apache2-doc
-rw-r--r-- 1 root root  269 Dez 22  2014 charset
-rw-r--r-- 1 root root 3296 Dez 22  2014 localized-error-pages
lrwxrwxrwx 1 root root   23 Jan 31  2015 munin -> ../../munin/apache.conf
-rw-r--r-- 1 root root  143 Dez 22  2014 other-vhosts-access-log
lrwxrwxrwx 1 root root   28 Jan 24  2015 phpmyadmin.conf -> ../../phpmyadmin/apache.conf
-rw-r--r-- 1 root root 2753 Jan 23  2015 security



Oben genannte Dateinamen, einige Verzeichnisse und die Syntax in den Direktiven sind ab Apache Version 2.4.x nicht mehr gültig.





Beispiel ab Apache Version 2.4.x:

Alle Verfügbaren VirtualHost's im Verzeichnis „/etc/apache2/conf-available“ anzeigen.

root@home:/etc/apache2/sites-available# ll
insgesamt 12
-rw-r--r-- 1 root root 1327 Mär 17 06:28 000-default.conf
-rw-r--r-- 1 root root 6432 Mär 17 07:33 default-ssl.conf


Die Verfügbaren VirtualHost Dateien werden ab Apache 2.4.x mit *.conf Endung erzeugt.


Die Datei „000-default.conf“ als Beispiel betrachtet:
FIXME

Anzeigen

Ausblenden

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /srv/www

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>




Alle aktiven VirtualHost's werden als symbolische Links im Verzeichnis „“ angezeigt.

root@home:/etc/apache2/sites-enabled# ll
insgesamt 0
lrwxrwxrwx 1 root root 35 Mär 17 07:34 000-default.conf -> ../sites-available/000-default.conf




Weitere VirtualHost Dateien sind seit Apache Version 2.4.x in folgenden Verzeichnissen:

root@home:/etc/apache2# ll
insgesamt 80
...
drwxr-xr-x 2 root root  4096 Mär 17 05:24 conf-available
drwxr-xr-x 2 root root  4096 Mär 17 05:21 conf-enabled
...



root@mir:/etc/apache2/conf-available# ll
insgesamt 28
-rw-r--r-- 1 root root  221 Jul  5  2016 apache2-doc.conf
-rw-r--r-- 1 root root  315 Jul  5  2016 charset.conf
-rw-r--r-- 1 root root  127 Jul 29  2013 javascript-common.conf
-rw-r--r-- 1 root root 3224 Jul  5  2016 localized-error-pages.conf
-rw-r--r-- 1 root root  189 Jul  5  2016 other-vhosts-access-log.conf
lrwxrwxrwx 1 root root   28 Mär 17 05:24 phpmyadmin.conf -> ../../phpmyadmin/apache.conf
-rw-r--r-- 1 root root 2190 Aug  7  2016 security.conf
-rw-r--r-- 1 root root  455 Jul  5  2016 serve-cgi-bin.conf



Im Verzeichnis „/etc/apache2/conf-available“ sind weitere VirtualHost's und Aliase, die mit der Endung *.conf Erzeugt werden. Die weiteren aktiven VirtualHost's werden im Verzeichnis „/etc/apache2/conf-enabled“ als symbolische Links erzeugt.

root@mir:/etc/apache2/conf-enabled# ll
insgesamt 0
lrwxrwxrwx 1 root root 34 Nov 11  2016 apache2-doc.conf -> ../conf-available/apache2-doc.conf
lrwxrwxrwx 1 root root 30 Nov 11  2016 charset.conf -> ../conf-available/charset.conf
lrwxrwxrwx 1 root root 40 Mär 17 05:19 javascript-common.conf -> ../conf-available/javascript-common.conf
lrwxrwxrwx 1 root root 44 Nov 11  2016 localized-error-pages.conf -> ../conf-available/localized-error-pages.conf
lrwxrwxrwx 1 root root 46 Nov 11  2016 other-vhosts-access-log.conf -> ../conf-available/other-vhosts-access-log.conf
lrwxrwxrwx 1 root root 33 Mär 17 05:21 phpmyadmin.conf -> ../conf-available/phpmyadmin.conf
lrwxrwxrwx 1 root root 31 Nov 11  2016 security.conf -> ../conf-available/security.conf
lrwxrwxrwx 1 root root 36 Nov 11  2016 serve-cgi-bin.conf -> ../conf-available/serve-cgi-bin.conf




Beispieldatei phpmyadmin.conf:
FIXME

Anzeigen

Ausblenden

# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_admin_flag allow_url_fopen Off
        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/
    </IfModule>

</Directory>

# Authorize for setup
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>





.htaccess


Mit der „.htaccess“ Datei kann man den Zugriff und die Sicherheit der Webverzeichnisse dezentral konfigurieren. „.htaccess“ Dateien können überall in den Webverzeichnissen verteilt werden. Bei jedem Zugriff auf ein Verzeichnis mit einer „.htaccess“ Datei wird diese zuvor eingelesen. Der Zugriffsschutz wird mit AllowOverride in den Webserver Einstellungen geregelt. Die verschiedenen Parameter können auch untereinander kombiniert werden. Hiermit kann ein Webverzeichnis auch durch ein Passwort geschützt werden. Es ist nicht auszuschließen, dass sich nicht alle Bot Systeme an diese Regeln halten.


  • AllowOverride None ⇒ Hier werden .htaccess Dateien igoriert.
  • AllowOverride All ⇒ Hier können alle erlaubten zentralen Vorgaben überschrieben werden.
  • AllowOverride Options ⇒ In den .htaccess Dateien können Anweisungen zur Steuerung spezieller Verzeichniseigenschaften festgelegt werden.
  • AllowOverride Limit ⇒ Es können Zugriffe von bestimmten Hosts erlaubt oder Verboten werden.
  • AllowOverride Indexes ⇒ Hier sind Anweisungen zur Steuerung von Verzeichnisindizes zulässig.
  • AllowOverride FileInfo ⇒ Hier können Anweisungen zu bestimmten Dokumententypen festgelegt werden.
  • AllowOverride AuthConfig ⇒ In einer .htaccess Datei können Autorisierungsanweisungen stehen.




Um den Zugriff auf ein Webverzeichnis mit einem Passwort zu schützen, kann die „.htaccess“ Datei wie folgt angepasst werden. Mit AuthUserFile wird auf die Datei verwiesen, in der die Nutzernamen und Passwörter festgelegt sind (Nutzername:Hash).

AuthType Basic
AuthName "Geschützter Bereich"
AuthUserFile /pfad/zur/.htpasswd
Require valid-user

Beispiel: (.htaccess)


Nutzername1:$apr1$m0OaZVp0$9OHApAf65z24vNUZts8Zz1
Nutzername2:$safdgsaZGTR$f65z24vhukghj$1ooTb76jo9

Beispiel: (.htpasswd)


Für bestimmte Nutzer Bereiche können Rechte festgelegt werden.

# .htaccess-Datei für Web-Verzeichnis /redaktion
AuthType Basic
AuthName "Service-Bereich"
AuthUserFile /usr/redaktion/web/.htusers
AuthGroupFile /usr/redaktion/web/.htgroups
Require user  Peter Olli Patti
Require group Redakteure




IP Adressbereiche oder Namensadressen ausschließen:

# .htaccess Datei zum Regeln von IP-Bereichen
Order deny,allow
Deny from .aol.com
Deny from 192.168
Allow from 192.168.220.102

Ist auf dem Webserver ein Modul installiert, das eine URL abändern kann, dann können in der „.htaccess“ Datei auch Umleitungen definiert werden.

Anzeigen

Ausblenden

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^aipbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Ants.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^asterias [OR]
RewriteCond %{HTTP_USER_AGENT} ^.attach.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Alexibot [OR]
RewriteCond %{HTTP_USER_AGENT} ^BackDoorBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^.BackWeb.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^.Bandit.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Black [OR]
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^BlowFish [OR]
RewriteCond %{HTTP_USER_AGENT} ^BotALot [OR]
RewriteCond %{HTTP_USER_AGENT} ^BuiltBotTough [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bloggsi [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Buddy.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Bullseye [OR]
RewriteCond %{HTTP_USER_AGENT} ^BunnySlippers [OR]
RewriteCond %{HTTP_USER_AGENT} ^Cegbfeieh [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^CHATCATCHER [OR]
RewriteCond %{HTTP_USER_AGENT} ^CheeseBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^CherryPicker [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Crawler.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Crescent [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Collector.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Convera [OR]
RewriteCond %{HTTP_USER_AGENT} ^CopyRightCheck [OR]
RewriteCond %{HTTP_USER_AGENT} ^cosmos [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Copier.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DataFountains [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DittoSpyder [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Downloader.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^grub [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^HTTP://WWW.RELEVANTNOISE.COM [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^Java [OR]
RewriteCond %{HTTP_USER_AGENT} ^JAVA [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^looksmart [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^LMSPIDER [OR]
RewriteCond %{HTTP_USER_AGENT} ^lmspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^MoreOverBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Navroad.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net [OR]
RewriteCond %{HTTP_USER_AGENT} ^NICErsPRO [OR]
RewriteCond %{HTTP_USER_AGENT} ^NPBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetMechanic [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^PYTHON-URLLIB [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Reaper.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^.Recorder.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^RepoMonkey [OR]
RewriteCond %{HTTP_USER_AGENT} ^RMA [OR]
RewriteCond %{HTTP_USER_AGENT} ^SHELOB [OR]
RewriteCond %{HTTP_USER_AGENT} ^SIMILARPAGES [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Siphon.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Snake.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^.Snagger.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^SphereScout [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Sucker.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^.SuperBot.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Surfbot.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^.*Stripper.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^SlySearch [OR]
RewriteCond %{HTTP_USER_AGENT} ^Snoopy [OR]
RewriteCond %{HTTP_USER_AGENT} ^SpankBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^spanner [OR]
RewriteCond %{HTTP_USER_AGENT} ^Super [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^suzuran [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport [OR]
RewriteCond %{HTTP_USER_AGENT} ^Telesoft [OR]
RewriteCond %{HTTP_USER_AGENT} ^thesubot [OR]
RewriteCond %{HTTP_USER_AGENT} ^.thesubot.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Teleport.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^The.Intraformant [OR]
RewriteCond %{HTTP_USER_AGENT} ^TheNomad [OR]
RewriteCond %{HTTP_USER_AGENT} ^TightTwatBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^Titan [OR]
RewriteCond %{HTTP_USER_AGENT} ^turingos [OR]
RewriteCond %{HTTP_USER_AGENT} ^TurnitinBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^URLy.Warning [OR]
RewriteCond %{HTTP_USER_AGENT} ^VCI [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Vacuum.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^web [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebBandit [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*WebZIP.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^weneo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Wget.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^.Whacker.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^.Widow.*$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^www [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^YANDEX [OR]
RewriteCond %{HTTP_USER_AGENT} ^YandexBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus [OR]
RewriteCond %{QUERY_STRING} .*’.* [OR]
RewriteCond %{QUERY_STRING} .*%27.* [OR]
RewriteCond %{QUERY_STRING} .*”.* [OR]
RewriteCond %{QUERY_STRING} .*%22.* [OR]
RewriteCond %{QUERY_STRING} .*`.* [OR]
RewriteCond %{QUERY_STRING} .*%60.* [OR]
RewriteCond %{QUERY_STRING} .*%25.* [OR]
RewriteCond %{QUERY_STRING} .*echr.* [OR]
RewriteCond %{QUERY_STRING} .*esystem.* [OR]
RewriteCond %{QUERY_STRING} .*passthru.* [OR]
RewriteCond %{QUERY_STRING} .*wget.* [OR]
RewriteCond %{REMOTE_ADDR} =87.98.166.194
RewriteRule ^.* - [F]

<Files .htaccess>
order allow,deny
deny from all
</Files>




Eine Ausführliche Beschreibung gibt es auf der Self-Html Seite.






  • mod_cgi.so ⇒ Modul zum laden von CGI Dateien.
  • libphp5.so ⇒ Modul zur Darstellung von PHP Webseiten.
  • mod_ssl.so ⇒ Modul zum aufsetzen eines https Servers.




mods-available / mods-enabled


Dieses Verzeichnis enthält diverse Apache Module. Wenn man weitere Module aktivieren will, werden Links auf diese Dateien gesetzt. In „mods-available“ befinden sich die Konfigurationsdateien, in „mods-enabled“ die Links auf die aktivierten Module.


Syntax:

  • a2enmod ⇒ aktiviert man Module
  • a2dismod ⇒ deaktiviert man Module




Beispiel:

sudo a2enmod mod_python

Pyton Modul hinzufügen.

oder …

sudo a2enmod python




Als nächstes sollte noch die VirtualHost Datei im Verzeichnis „/etc/apache2/sites-available/“ angepasst werden.

<Directory /[var,srv]/www>
  ...
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug on
</Directory>






Common Gateway Interface (CGI) bezeichnet eine Schittstelle zwischen einem Programm und dem Webserver. Diese Programme werden als der Benutzer gestartet, mit dem Apache konfiguriert und gestartet ist.

Die Programme bekommen die von der URL übergebenen GET Parameter, diese werden dann interprtiert als Datenstrom weitergegeben. Mit POST gesendete Daten muß das Programm selbst den Datenstrom interpretieren. Die Eingaben kommen dann von STDIN und Ausgaben auf STDOUT.


Beispiel eines CGI Scriptes in Pearl:

#!/usr/bin/pearl
#
# CGI Antwort Header
#
# Zu beachten ist, dass eine weitere Leerzeile angehängt werden muß
print "Content-type: text/html\n\n";

# Ausgabe an STDOUT
print <<<EOF;
<html>
<head>
<title>Pearl CGI Script</title>
</head>
<body>
<h1>CGI Programm</h1>
is running
</body>
</html>
EOF

exit;




Die Datei sollte dann im CGI Verzeichnis des Apache gespeichert werden und ausführbar sein. Der Pfad wäre dann „www.<domain.de>/<cgi-verzeichnis>/*.pl“.


Das Skript kann auch als Bash Shellskript angelegt werden:

#!/bin/bash

echo "content-type: text/html"
echo
echo
echo "<html><head><title>Shell CGI Script</title></head>"
echo "<body>"
echo "Parameter: $OUERY_STRING"
echo "</body></html>"

Die Datei muß ebenfalls ausführbar sein. Der Pfad wäre dann „www.<domain.de>/<cgi-verzeichnis>/*.sh?wert=cul“.


CGI Skripte sind leicht komprimitierbar. Achten Sie hier sehr auf die Sicherheit des Servers und des Nutzers.






SSL verschlüsselt den Http Datenstrom auf Protokollebene. Ein auf öffentliche Schlüssel und Zertifikaten festgelegtes Verfahren zum Aufbau einer gesicherten TCP/IP Verbindung von Server und Client.

SSL verwendet dabei assymetrische Verschlüsselungsverfahren zur Identifizierung zwischen Server und Client. Heute arbeiten fast alle Zugänge auf dem Algorythmus AES mit einer Schlüssellänge mit 256Bit, gebräuchliche Algorytmen sind RC2, RC4, DES, Triple DES, IDEA. Bei der ersten Verbindung wird dann ein gemeinsamer Nenner zwischen Algoritmus und Schlüssellänge ausgehandelt. Die Ausgabe erfolgt dann über Port 443.


Bevor der Websever für https:// konfiguriert wird, sollte man sicherstellen, dass der Apache Webserver unter einer http:// verbindung erreichbar ist. Das Paket „openssl“ muß hierfür installiert sein.




Syntax:

  • openssl [command] [opt] [args]





Einrichten einer Https Verindung via SSL


In diesem Beispiel wird eine verschlüsselte Https Konfiguration eingerichtet. Nutzt man für verschiedene Dienste jeweils einen eigenen SSL Schlüssel, kann man hierfür auch verschiedene Unterverzeichnisse anlegen, um die Übersicht zu behalten.


root@host:# mkdir -p /etc/ssl/localcerts/my-cert-dir




Mit dem Kommando „openssl“ wird jetzt der Schlüssel generiert.

root@host:~# openssl req -new -x509 -days 365 -nodes -out /etc/ssl/localcerts/my-cert-dir/apache-cert-name.pem -keyout /etc/ssl/localcerts/my-cert-dir/apache-cert-name.key



Generating a 1024 bit RSA private key
....++++++
.................++++++
writing new private key to '/etc/ssl/localcerts/my-cert-dir/apache-cert-name.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.

Country Name (2 letter code) [AU]:DE
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:company
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:Zaphod Beeblebrox
Email Address []:




Das Zertifikat und der Schlüssel wurden jetzt im Verzeichnis „/etc/ssl/localcerts/my-cert-dir/“ erstellt. Die Nutzerrechte der Dateien sollten noch auf 600 geändert werden.

root@host:/etc/ssl/localcerts/my-cert-dir# chmod 600 apache-cert-name*
root@host:/etc/ssl/localcerts/my-cert-dir# ll
insgesamt 8
-rw------- 1 root root  887 16. Jan 00:58 apache-cert-name.key
-rw------- 1 root root 1062 16. Jan 00:58 apache-cert-name.pem




Jetzt sollte sichergestellt sein, dass das SSL Modul aktiviert ist.




root@host:~# a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
Run '/etc/init.d/apache2 restart' to activate new configuration!




Die jeweilige VirtualHost Datei im Verzeichnis „/etc/apache2/sites-available“ sollte noch angepasst werden.

NameVirtualHost *:443 
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/apache-cert-name.pem
SSLCertificateKeyFile /etc/ssl/localcerts/apache-cert-name.key
...




Der VirtualHost kann nun aktiviert werden.

a2ensite <VirtualHost Datei oder default>




Es muß jetzt noch dafür gesorgt werden, dass der Webserver auf dem Port 443 lauscht. Bei Debian Systemen kann dies der Datei „/etc/apache2/ports.conf“ vorgenommen werden.

Listen 443
Listen 80




Ein Neustart des Webservers übernimmt die vorgenommenen Änderungen:

/etc/init.d/apache2 restart



oder …

service apache2 restart




Die Webseite kann jetzt unter https://Serveradresse aufgerufen werden:






Wird bei sensiblen Formulareingaben und wichtigen Dokumenten benötigt wie E-Mails, Online Banking usw. Server Zertifikate werden meist an verantwortliche Personen oder Betriebe gebunden. Die meisten Browser kennen die Zertifizierungsstellen und überprüfen die Serverzertifikate anhand ihres Zertifizierungspfads.

Nach der Installation unter Debian werden unter dem Verzeichnis „/etc/apache2/ssl.*“, Dummy Dateien angelegt.


TLS Testen:

apache2 -S -DSSL




Apache sollte jetzt gestoppt und neugestartet werden.

apache2ctl stop
#
apache2ctl startssl



FIXME




WebDAV erlaubt den Zugriff auf Dateien eines Servers. Mit WebDAV zur Verfügung gestellte Dateien können mit dem Windows-Datei, Internet-Explorer und dem MacOS-X Finder angesprochen werden.


Zuerst müssen die Module [dav] und [dav.ds] geladen werden. Dann muß der Konfigurationsdatei eine Direktive für einen Dateiblockmechanismus in der Datei „/etc/apache2/apache2.conf“ angefügt werden.

...
DavLockDB /var/lock/apache2/lockDav
...




Das Verzeichnis muß angelegt und Benutzer und Gruppenrechte auf „www-data“ eingestellt sein. DAV wird nun in der VirtualHost Datei eingeschalten.

<Directory /srv/www/daten>
    # DAV einschalten
    DAV On
    # Liefert z.B. PHP Dateien aus, wird vom Server aber nicht vorab Interpretiert
    ForceType plain/text
    # .htaccess Dateien wirken nicht
    AllowOverride None
    # Indexdarstellung erlauben
    Options Indexes
</Directory>

Das „/daten“ Verzeichnis ist jetzt für jeden zugänglich, durch ForceType wird verhindert, dass der Server beim Neustart neue Skripte lädt. Mit der Option AllowOverride wird verhindert, dass „.htaccess“ Dateien Direktiven einschleusen.

In kombination mit AuthType Basic kann ein Verzeichnis vor Up und Downloads gesichert werden. Die Direktive SSLRequireSSL verschlüsselt Zugriffe.

FIXME




Falscher Zeichensatz


Wenn es bei der Ausgabe Probleme mit dem Zeichensatz gibt kann man den Apache in der Datei „/etc/apache2/conf.d/charset“ von utf-8 auf ISO-8859-1 umstellen.


Überprüfen lässt sich der PHP Zeichensatz mit der Datei:

<?php phpinfo(); ?>




In den Zeilen HTTP Headers Information → HTTP Response Headers → Content-Type → charset befindet sich die Information zum Zeichensatz.

Konfigurieren kann man das in der Datei „/etc/php5/apache2/php.ini“ und „/etc/apache2/conf.charset“.



Kein Hostname




Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName




Bei dieser Fehlermeldung kann man in der Datei „/etc/apache2/apache2.conf“ den Hostname und Domain eintragen.

ServerName localhost



FIXME

Wird der ServerName nicht wirksam sollte man die Einstellung UseCanonicalName Off in der Konfigurations Datei „/etc/apache2/apache2.conf“ verwenden.





Quellen und weitere Links

Cloud

  • Zuletzt geändert: 06.11.2018 22:39
  • von Tom