ubuntu:apache_webserver
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| ubuntu:apache_webserver [2019/06/20 23:37] – [Cerbot: Zertifikate anfordern und Webserver anpassen] Befehl Sebastian Hetzel | ubuntu:apache_webserver [2022/11/06 15:28] (aktuell) – [Certbot installieren] Sebastian Hetzel | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Ubuntu 18.04: Apache Webserver ====== | + | ====== Ubuntu 18.04 und 20.04 und 22.04: Apache Webserver ====== |
| + | {{: | ||
| + | |||
| + | Ich verwende in dieser Anleitung das MPM ITK - http:// | ||
| + | |||
| + | ===== Installation der Pakete ===== | ||
| + | |||
| + | < | ||
| + | # aptitude install apache2 libapache2-mpm-itk | ||
| + | </ | ||
| + | |||
| + | ===== Konfigurationsanpassungen ===== | ||
| + | |||
| + | Ist Apache installiert, | ||
| + | |||
| + | <file | / | ||
| + | [...] | ||
| + | # | ||
| + | # ServerTokens | ||
| + | # This directive configures what you return as the Server HTTP response | ||
| + | # Header. The default is ' | ||
| + | # and compiled in modules. | ||
| + | # Set to one of: Full | OS | Minimal | Minor | Major | Prod | ||
| + | # where Full conveys the most information, | ||
| + | # | ||
| + | ServerTokens Prod | ||
| + | [...] | ||
| + | </ | ||
| + | |||
| + | Sicherheistskritische Module ausschalten: | ||
| + | |||
| + | < | ||
| + | # a2dismod info | ||
| + | # a2dismod status | ||
| + | </ | ||
| + | ===== 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, | ||
| + | exit 0 | ||
| + | |||
| + | arr=(user1 user2 user3) | ||
| + | |||
| + | for item in ${arr[*]} | ||
| + | do | ||
| + | mkdir -p / | ||
| + | mkdir -p / | ||
| + | mkdir -p / | ||
| + | useradd -d "/ | ||
| + | chown -R $item.$item / | ||
| + | done | ||
| + | |||
| + | exit 0 | ||
| + | </ | ||
| + | |||
| + | ===== Virtuellen Host konfigurieren ===== | ||
| + | |||
| + | Folgend eine Beispielkonfiguration, | ||
| + | |||
| + | < | ||
| + | < | ||
| + | ServerAdmin webmaster@meine-domain.de | ||
| + | ServerName meine-domain.de | ||
| + | ServerAlias www.meine-domain.de | ||
| + | DocumentRoot / | ||
| + | |||
| + | # Mod ITK configuration | ||
| + | < | ||
| + | AssignUserId meine-domain meine-domain | ||
| + | </ | ||
| + | |||
| + | |||
| + | < | ||
| + | Options +Includes +MultiViews -Indexes +FollowSymLinks | ||
| + | AllowOverride AuthConfig FileInfo Options | ||
| + | Require all granted | ||
| + | </ | ||
| + | |||
| + | ErrorLog / | ||
| + | |||
| + | # Possible values include: debug, info, notice, warn, error, crit, | ||
| + | # alert, emerg. | ||
| + | LogLevel warn | ||
| + | |||
| + | CustomLog / | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Der virtuelle Host muss noch aktiviert werden. Hinter dem Befehl '' | ||
| + | |||
| + | < | ||
| + | # a2ensite meine-domain | ||
| + | # apache2ctl configtest | ||
| + | # service apache2 reload | ||
| + | </ | ||
| ===== HTTPS mit Let's Encrypt ===== | ===== HTTPS mit Let's Encrypt ===== | ||
| ==== Certbot installieren ==== | ==== Certbot installieren ==== | ||
| - | Als root ausführen: | + | Für Ubuntu 18.04 musste noch ein PPA eingebunden werden. |
| + | Bitte nachfolgende Befhele als root ausführen: | ||
| < | < | ||
| Zeile 15: | Zeile 115: | ||
| apt-get install python-certbot-apache</ | apt-get install python-certbot-apache</ | ||
| + | Ab Ubuntu 20.04 ist dies nicht mehr notwendig: | ||
| + | |||
| + | Folgende Anleitung verwenden (snapd): | ||
| + | > https:// | ||
| ==== Cerbot: Zertifikate anfordern und Webserver anpassen ==== | ==== Cerbot: Zertifikate anfordern und Webserver anpassen ==== | ||
| Zeile 22: | Zeile 126: | ||
| # certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email certadmin@meine-domain.de --domain www.meine-domain.de --domain meine-domain.de | # 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 | ||
| + | 35 7 * * * / | ||
| + | </ | ||
| + | |||
| + | ==== Verschlüsselung: | ||
| + | |||
| + | <file | / | ||
| + | # 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, | ||
| + | SSLProtocol | ||
| + | SSLCipherSuite | ||
| + | SSLHonorCipherOrder | ||
| + | SSLCompression | ||
| + | |||
| + | SSLOptions +StrictRequire | ||
| + | |||
| + | # Add vhost name to log entries: | ||
| + | LogFormat "%h %l %u %t \" | ||
| + | LogFormat "%v %h %l %u %t \" | ||
| + | |||
| + | #CustomLog / | ||
| + | #LogLevel warn | ||
| + | #ErrorLog / | ||
| + | |||
| + | # Always ensure Cookies have " | ||
| + | #Header edit Set-Cookie (? | ||
| + | </ | ||
| + | |||
| + | In der Konfiguration des virtuellen Hosts: | ||
| + | |||
| + | < | ||
| + | [...] | ||
| + | < | ||
| + | | ||
| + | </ | ||
| + | [...] | ||
| + | </ | ||
| + | ===== Logfiles rotieren lassen ===== | ||
| + | |||
| + | <file | / | ||
| + | / | ||
| + | daily | ||
| + | missingok | ||
| + | rotate 14 | ||
| + | compress | ||
| + | delaycompress | ||
| + | notifempty | ||
| + | create 640 root adm | ||
| + | sharedscripts | ||
| + | postrotate | ||
| + | if invoke-rc.d apache2 status > /dev/null 2>& | ||
| + | invoke-rc.d apache2 reload > /dev/null 2>& | ||
| + | fi; | ||
| + | endscript | ||
| + | prerotate | ||
| + | if [ -d / | ||
| + | run-parts / | ||
| + | fi; \ | ||
| + | endscript | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== PHP ===== | ||
| + | |||
| + | < | ||
| + | # aptitude install php php-cli php-json php-pdo php-mysql php-zip php-gd | ||
| + | </ | ||
| + | |||
| + | ===== ModSecurity ===== | ||
| + | |||
| + | Dieses Apache-Modul erkennt Angriffmuster (z. B. Session Hijacking, Cross-Site-Scripting) und verweigert bei Angriff die Anfrage. | ||
| + | |||
| + | ==== Installation ==== | ||
| + | |||
| + | < | ||
| + | |||
| + | ==== Konfiguration ==== | ||
| + | |||
| + | < | ||
| + | cd / | ||
| + | cp modsecurity.conf-recommended modsecurity.conf | ||
| + | </ | ||
| + | |||
| + | ModSecurity sollte nun im DetectOnly-Modus laufen und erkannte Angriffsmuster unter ''/ | ||
| + | |||
| + | Dies kann folgendermaßen geändert werden: | ||
| + | |||
| + | <file |h / | ||
| + | [...] | ||
| + | # Enable ModSecurity, | ||
| + | # only to start with, because that minimises the chances of post-installation | ||
| + | # disruption. | ||
| + | # | ||
| + | # | ||
| + | SecRuleEngine On | ||
| + | [...] | ||
| + | </ | ||
| + | |||
| + | <file |h / | ||
| + | [...] | ||
| + | # Log everything we know about a transaction. | ||
| + | # | ||
| + | SecAuditLogParts ABCEFHJKZ | ||
| + | [...] | ||
| + | </ | ||
| + | |||
| + | ==== Aktuelles OWASP Core Rule Set ==== | ||
| + | |||
| + | < | ||
| + | cd / | ||
| + | git clone https:// | ||
| + | cd owasp-modsecurity-crs | ||
| + | cp crs-setup.conf.example crs-setup.conf | ||
| + | </ | ||
| + | |||
| + | Das Regelwerk hinterlegen: | ||
| + | |||
| + | <file |h / | ||
| + | < | ||
| + | # Default Debian dir for modsecurity' | ||
| + | SecDataDir / | ||
| + | |||
| + | # Include all the *.conf files in / | ||
| + | # Keeping your local configuration in that directory | ||
| + | # will allow for an easy upgrade of THIS file and | ||
| + | # make your life easier | ||
| + | # IncludeOptional / | ||
| + | IncludeOptional / | ||
| + | IncludeOptional / | ||
| + | IncludeOptional / | ||
| + | |||
| + | # Include OWASP ModSecurity CRS rules if installed | ||
| + | # IncludeOptional / | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Aktualisieren kann man das Ruleset, indem man einfach eine aktuelle Kopie von github zieht und diese in sein Conf-Verzeichnis kopiert. Bitte vorher die Konfig-Dateien an Seite legen. | ||
| + | |||
| + | ==== Logfiles ==== | ||
| + | |||
| + | Da sehr viele Daten geloggt werden, sollte man das Logfile täglich rotieren lassen: | ||
| + | |||
| + | <file |h / | ||
| + | / | ||
| + | { | ||
| + | rotate 14 | ||
| + | daily | ||
| + | missingok | ||
| + | compress | ||
| + | delaycompress | ||
| + | notifempty | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Regelausnahmen: | ||
| + | |||
| + | === Virtuellen Host anpassen für WebDAV === | ||
| + | |||
| + | < | ||
| + | [...] | ||
| + | < | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | [...] | ||
| + | </ | ||
| + | |||
| + | === Ausnahmeregelungen für Nextcloud === | ||
| + | |||
| + | <file | REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf> | ||
| + | [...] | ||
| + | # Own ip address not monitored | ||
| + | SecRule REMOTE_ADDR " | ||
| + | |||
| + | SecRule REQUEST_URI " | ||
| + | </ | ||
| + | |||
| + | === Globale Ausnahme-Presets für Nextcloud === | ||
| + | |||
| + | Achtung: Gilt für alle virtuellen Hosts! | ||
| + | |||
| + | <file | > | ||
| + | [...] | ||
| + | SecAction \ | ||
| + | " | ||
| + | phase:1,\ | ||
| + | nolog,\ | ||
| + | pass,\ | ||
| + | t:none,\ | ||
| + | setvar: | ||
| + | [...] | ||
| + | </ | ||
| + | |||
| + | > https:// | ||
ubuntu/apache_webserver.1561066639.txt.gz · Zuletzt geändert: von Sebastian Hetzel
