Apache Virtual Host Datei finden und ergänzen (für HSTS)

Hallo, meine Nextcloud Installation (Raspberry Pi, Apache) gibt noch eine weitere Warnung aus:

The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the security tips.

Nach einiger Recherche glaube ich folgende Zeilen in der Apache Virtual Host Datei ergänzen zu müssen:

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

Nun habe ich die gesamte SSL Installation mit zwei Certbot Anweisungen erledigt und bin daher mit der Konfiguration leider nicht sonderlich firm. Ich vermute, dass eine der folgenden Dateien die gesuchte Virtual Host Datei ist:

/etc/apache2/sites-enabled/000-default.conf
/etc/apache2/sites-enabled/000-default-le-ssl.conf
/etc/apache2/sites-available/000-default.conf
/etc/apache2/sites-available/000-default-le-ssl.conf
/etc/apache2/sites-available/default-ssl.conf

Kann das jemand verifizieren? Oder bin ich bereits irgendwo falsch abgebogen?

Vielen Dank!

Das ist schon das richtige Verzeichnis. Wirksam sind nur die Einträge in /etc/apache2/sites-enabled. Dies sind symbolische Links zu den gleichnamigen Dateien in sites-available. In den beiden Dateien

/etc/apache2/sites-available/000-default.conf
/etc/apache2/sites-available/000-default-le-ssl.conf

solltest du Hinweise auf deine Nextcloud Installation finden. Hier kannst du auch den Header eintragen. Es reicht wohl, den Header in der ssl.conf einzutragen, wenn du den Zugang über https benutzt.

Danke, so sieht meine /etc/apache2/sites-available/000-default-le-ssl.conf Datei aus:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # 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 /var/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


ServerName ddns.meine-domain.de
SSLCertificateFile /etc/letsencrypt/live/ddns.meine-domain.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ddns.meine-domain.de/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Ich hänge das jetzt einfach mal darunter und starte Apache neu:

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

Edit: DIe Meldung ist leider noch immer da, auch wenn ich die drei Zeilen direkt über < /VirtualHost> setze, siehe: https://docs.nextcloud.com/server/17/admin_manual/installation/harden_server.html

Was ist denn wirklich das Verzeichnis, in dem du NC installiert hast? Ist es wirklich
/var/www/html

? Sinnvoll ist z.B. /var/www/nextcloud dann sind keine Verwechslungen möglich. Der Inhalt des Verzeichnisses sollte etwa so aussehen:

drwxr-xr-x 33 www-data www-data  4096 Nov 10 11:29 3rdparty
drwxr-x--- 51 www-data www-data  4096 Nov 10 11:47 apps
-rw-r--r--  1 www-data www-data 12063 Nov 10 11:29 AUTHORS
drwxr-x---  2 www-data www-data  4096 Nov 10 11:47 config
-rw-r--r--  1 www-data www-data  3805 Nov 10 11:29 console.php
-rw-r--r--  1 www-data www-data 34520 Nov 10 11:29 COPYING
drwxr-xr-x 23 www-data www-data  4096 Nov 10 11:29 core
-rw-r--r--  1 www-data www-data  4993 Nov 10 11:29 cron.php
-rw-r--r--  1 www-data www-data   156 Nov 10 11:29 index.html
-rw-r--r--  1 www-data www-data  3172 Nov 10 11:29 index.php
drwxr-xr-x  6 www-data www-data  4096 Nov 10 11:29 lib
-rw-r--r--  1 www-data www-data   283 Nov 10 11:29 occ
drwxr-xr-x  2 www-data www-data  4096 Nov 10 11:29 ocm-provider
drwxr-xr-x  2 www-data www-data  4096 Nov 10 11:29 ocs
drwxr-xr-x  2 www-data www-data  4096 Nov 10 11:29 ocs-provider
-rw-r--r--  1 www-data www-data  2951 Nov 10 11:29 public.php
-rw-r--r--  1 www-data www-data  5139 Nov 10 11:29 remote.php
drwxr-xr-x  4 www-data www-data  4096 Nov 10 11:29 resources
-rw-r--r--  1 www-data www-data    26 Nov 10 11:29 robots.txt
drwxr-xr-x 13 www-data www-data  4096 Nov 10 11:29 settings
-rw-r--r--  1 www-data www-data  2287 Nov 10 11:29 status.php
drwxr-x---  3 www-data www-data  4096 Nov 10 11:29 themes
drwxr-x---  2 www-data www-data  4096 Nov 10 11:46 updater
-rw-r--r--  1 www-data www-data   362 Nov 10 11:29 version.php

Das Verzeichnis ist ‘/var/www/html/nextcloud’. Die ‘000-default-le-ssl.conf’ hat wohl Certbot erstellt oder zumindest konfiguriert. Ich habe die ganze SSL Installation mit nur zwei Befehlen durchgeführt:

 sudo apt-get install python-certbot-apache
 sudo certbot --apache

-> E-Mail Adresse eingeben
-> 'Terms of Service' mit 'A'/Enter bestätigen
-> 'Newsletter' mit 'N'/Enter ablehnen
-> Domain eingeben, z.B. ddns.meine-domain.de    
-> HTTP mit '2'/Enter automatisch auf HTTPS umleiten

Die Apache Startseite leite ich mit einer .htaccess Datei um:

sudo touch /var/www/html/.htaccess
sudo nano /var/www/html/.htaccess

-> folgende Zeilen einfügen
# 301 Redirect
RewriteEngine on
RewriteBase /
RewriteRule (.*) /nextcloud/$1 [R=301,L]

-> Anmerkung: In der Apache Konfiguration (/etc/apache2/apache2.conf) muss wohl der Eintrag 'AllowOverride' unter '<Directory /var/www/>' auf 'All' gesetzt sein. (Default: None)

Wie die ‘000-default-le-ssl.conf’ aussehen soll, ist mir leider noch nicht ganz klar, ich sehe mir das nochmal am Abend an. Schöne Grüße!

In die /etc/apache2/apache2.conf trägst du gar nichts ein. Das kommt alles in die vhost Datei, also in
000-default-le-ssl.conf. Dort sollte also stehen:

DocumentRoot /var/www/html/nextcloud

<Directory /var/www/html/nextcloud>


AllowOverride All
Require all granted

</Directory>

Neben den anderen Einträgen. Dann brauchst du meiner Meinung nach auch nicht die Umleitung in der .htaccess. Ich habe die jedenfalls nicht.

Es wäre auch eine gute Idee, die vhost Datei anders zu benennen, etwa
/etc/apache2/sites-available/nextcloud-ssl.conf
Du willst ja später evtl noch weitere vhosts einrichten.

Vielen Dank! Ich habe die ‘.htaccess’ gelöscht und den Eintrag in der ‘apache2.conf’ wieder von ‘All’ auf ‘None’ zurückgesetzt. Die genannten Ergänzungen habe ich in der ‘000-default-le-ssl.conf’ und ‘000-default.conf’ durchgeführt. Soweit klappt auch alles, nur die Zeilen aus dem Ausgangsposting muss ich erst irgendwo unterbringen ^^

Die kommen auch in die vhost-Datei. Das hast du in dem Ausgangsposting ja selbst geschrieben.

Ja, aber ich verstehe den Syntax nicht, egal wo und wie ich es probiere, es klappt einfach nicht. Die Warnung im Administrator Menü verschwindet nicht bzw. lässt sich der Server bei manchen Varianten nicht mehr neustarten.

Sind die headers in Apache aktiviert?

sudo a2enmod headers

Die Anweisung von oben kommt ausserhalb von
<Directory ...>...</Directory>

aber noch innerhalb von

<VirtualHost...> .... </VirtualHost>

Fehlermeldungen findest du in

/var/log/apache2/error.log
das hilft meist weiter.

1 Like

Danke, mit ‘sudo a2enmod headers’ hat es endlich geklappt. Hier zur Volsständigkeit noch meine ‘000-default-le-ssl.conf’ Datei:

IfModule mod_ssl.c>
<VirtualHost *:443>
        # 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 /var/www/html/nextcloud
        <Directory /var/www/html/nextcloud>
        Require all granted
        AllowOverride All
        </Directory>

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

        # 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


ServerName ddns.meine-domain.de
SSLCertificateFile /etc/letsencrypt/live/ddns.meine-domain.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ddns.meine-domain.de/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Hallo,

ich würde gerne das Thema nochmal aufgreifen wollen, da ich auch diesen Fehler habe.

Wenn ich die Datei “000-default-le-ssl.conf” in diesem Verzeichnis “/etc/apache2/sites-enabled/” oder in diesem “/etc/apache2/sites-available/” öffne, dann ist die Datei leer.

Ich bekomme diesen Fehler einfach nicht weg. Hat jemand eine genaue Schritt für Schritt Anleitung?

Mit freundlichen Grüßen

Hallo

Existiert die Datei bei dir überhaupt? Evtl. heisst deine Config Datei für Nextcloud ja anders? Ich nutze z.B. die Deafult Dateien gar nicht. Meine Datei heisst nextcloud-le-ssl.conf…

1 Like

Hey,

danke für die Antwort :slight_smile: daran hats gelegen :smiley:

Bei mir heißt die auch nextcloud…conf.

Jetzt funktioniert alles.

Super vielen Dank!

1 Like

Gern geschehen. :slight_smile: