Benutzer-Werkzeuge

Webseiten-Werkzeuge


ubuntu:apache_webserver

Dies ist eine alte Version des Dokuments!


Ubuntu 18.04 und 20.04: Apache Webserver

Ich verwende in dieser Anleitung das MPM ITK - http://mpm-itk.sesse.net/ .

Installation der Pakete

# aptitude install apache2 libapache2-mpm-itk

Konfigurationsanpassungen

Ist Apache installiert, ist er sofort einsatzbereit. Ich mache noch folgende Anpassungen:

/etc/apache2/conf-available/security.conf
[...]
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of:  Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens Prod
[...]

Webserver-User für virtuellen Host

Ich lege mittels eines Bash-Skripts die Benutzer und Verzeichnisse für die benötigten virtuellen Hosts an:

#!/bin/bash

# Sicherheitsstopp, vorher auskommentieren!
exit 0

arr=(user1 user2 user3)

for item in ${arr[*]}
do
        mkdir -p /srv/www/$item
        mkdir -p /srv/www/$item/htdocs
        mkdir -p /srv/www/$item/log
        useradd -d "/srv/www/$item" -s /bin/false $item
        chown -R $item.$item /srv/www/$item
done

exit 0

Virtuellen Host konfigurieren

Folgend eine Beispielkonfiguration, wie sie im Pfad /etc/apache2/sites-available abgelegt werden muss und mit einem Dateinamen, der mit .conf endet, benannt werden muss.

<VirtualHost *:80>
        ServerAdmin webmaster@meine-domain.de
        ServerName meine-domain.de
        ServerAlias www.meine-domain.de
        DocumentRoot /srv/www/meine-domain/htdocs

        # Mod ITK configuration
        <IfModule mpm_itk_module>
                AssignUserId meine-domain meine-domain
        </IfModule>


        <Directory "/srv/www/meine-domain/htdocs/">
                Options +Includes +MultiViews -Indexes +FollowSymLinks
                AllowOverride AuthConfig FileInfo Options
                Require all granted
        </Directory>

        ErrorLog /srv/www/meine-domain/log/error.log

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

        CustomLog /srv/www/meine-domain/log/access.log combined

</VirtualHost>

Der virtuelle Host muss noch aktiviert werden. Hinter dem Befehl a2ensite gehört der Dateiname des virtuellen Hosts ohne .conf.

# a2ensite meine-domain
# apache2ctl configtest
# service apache2 reload

HTTPS mit Let's Encrypt

Certbot installieren

Für Ubuntu 18.04 musste noch ein PPA eingebunden werden. Bitte nachfolgende Befhele als root ausführen:

apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-apache

Bei Ubuntu 20.04 ist dies nicht mehr notwendig:

aptitude install certbot
aptitude install python3-certbot-apache

Cerbot: Zertifikate anfordern und Webserver anpassen

Ein Beispiel:

# certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email certadmin@meine-domain.de --domain www.meine-domain.de --domain meine-domain.de

Cerbot: Zertifikatserneuerung testen

# certbot renew --dry-run

Cerbot Zertifikatserneuerung automatisieren

Als User root:

# crontab -e

Beispiel für die Crontab:

[...]
# m h  dom mon dow   command
35 7 * * * /usr/bin/certbot renew  >> /var/log/le-renew.log

Verschlüsselung: Protokolle und Ciphers

/etc/letsencrypt/options-ssl-apache.conf
# This file contains important security parameters. If you modify this file
# manually, Certbot will be unable to automatically provide future security
# updates. Instead, Certbot will print and log an error message with a path to
# the up-to-date file that you will need to refer to when manually updating
# this file.

SSLEngine on

# Intermediate configuration, tweak to your needs
SSLProtocol             all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS
SSLHonorCipherOrder     on
SSLCompression          off

SSLOptions +StrictRequire

# Add vhost name to log entries:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common

#CustomLog /var/log/apache2/access.log vhost_combined
#LogLevel warn
#ErrorLog /var/log/apache2/error.log

# Always ensure Cookies have "Secure" set (JAH 2012/1)
#Header edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4"

In der Konfiguration des virtuellen Hosts:

[...]
<IfModule mod_headers.c>
                 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
[...]

Logfiles rotieren lassen

/etc/logrotate.d/apache2
/var/log/apache2/*.log /srv/www/*/log/*.log {
        daily
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if invoke-rc.d apache2 status > /dev/null 2>&1; then \
                    invoke-rc.d apache2 reload > /dev/null 2>&1; \
                fi;
        endscript
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
}
ubuntu/apache_webserver.1602798220.txt.gz · Zuletzt geändert: von Sebastian Hetzel

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki