ubuntuusers.de

Apache rewrite in virtualhost zu https funktioniert nicht

Status: Ungelöst | Ubuntu-Version: Ubuntu 18.04 (Bionic Beaver)
Antworten |

paddy0174

Anmeldungsdatum:
20. Januar 2019

Beiträge: Zähle...

Hallo!

Ich habe mir einen kleinen Homeserver eingerichtet und stehe vor dem Problem, dass mein rewrite in der Virtualhost-Konfiguration nicht richtig funktioniert.

Server Eckdaten:

  • Ubuntu Server 18.04

  • Apache 2.4.29

  • mod_rewrite und mod_ssl sind enabled

  • Lets encrypt Zertifikat eingerichtet und ok

  • Nextcloud 15.0.2

  • alles hinter einer FritzBox 7490 / portforwarding für IP V4 und V6 auf ports 80 und 443

Enabled sind zwei Site configs, einmal sub.example.org.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<VirtualHost *:80>
        ServerName sub.example.org
        ServerAdmin me@example.org
        DocumentRoot /var/www/nextcloud/

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

        <Directory /var/www/nextcloud/>
                Options +FollowSymlinks
                AllowOverride All

                <IfModule mod_dav.c>
                        Dav off
                </IfModule>

                SetEnv HOME /var/www/nextcloud
                SetEnv HTTP_HOME /var/www/nextcloud
        </Directory>
        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
        </IfModule>

        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

</VirtualHost>

sowie die vom LE certbot erstellte sub.example.org-le-ssl.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin me@example.org
        ServerName sub.example.org
        DocumentRoot /var/www/nextcloud/

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

        <Directory /var/www/nextcloud/>
                Options +FollowSymlinks
                AllowOverride All

                <IfModule mod_dav.c>
                        Dav off
                </IfModule>

                SetEnv HOME /var/www/nextcloud
                SetEnv HTTP_HOME /var/www/nextcloud
        </Directory>

SSLCertificateFile /etc/letsencrypt/live/sub.example.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sub.example.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Es soll, zumindest momentan, nur die Nextcloud von aussen erreichbar sein, das klappt soweit gut unter der lokalen IP (192.168.xxx.xxx) und auch von aussen über dynDNS. Mein Problem ist, dass der Rewrite nur manchmal zu funktionieren scheint:

Im FF so wie es sein soll, lokale IP und Domain werden von http auf https umgeleitet. Chrome unter Android ebenfalls. Chrome und Opera hingegen verweigern die Umleitung und ich lande auf der FritzBox-Login-Seite (trotzdem weder myFritz noch Remotezugriff überhaupt aktiviert wären).

Ich bin für jede Hilfe dankbar, auch wenn Ihr andere Sachen bei diesem Aufbau seht, die beachtenswert wären!

Vielen Dank schonmal!

Berlin_1946 Team-Icon

Supporter, Wikiteam

Anmeldungsdatum:
18. September 2009

Beiträge: 10285

Hallo paddy0174,

hast du die DocumentRoot genau überprüft?

DocumentRoot /var/www/nextcloud/

paddy0174

(Themenstarter)

Anmeldungsdatum:
20. Januar 2019

Beiträge: 2

Vielen Dank für die Antwort! Ja, DocumentRoot stimmt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
paddy0174@nas:/var/www/nextcloud$ ls -la
total 164
drwxr-xr-x 15 www-data www-data  4096 Jan 15 23:38 .
drwxr-xr-x  3 root     root      4096 Jan 15 01:39 ..
drwxr-xr-x 32 www-data www-data  4096 Jan 11 19:34 3rdparty
drwxr-xr-x 44 www-data www-data  4096 Jan 15 22:24 apps
-rw-r--r--  1 www-data www-data 12063 Jan 11 19:33 AUTHORS
drwxr-xr-x  2 www-data www-data  4096 Jan 20 15:26 config
-rw-r--r--  1 www-data www-data  3650 Jan 11 19:33 console.php
-rw-r--r--  1 www-data www-data 34520 Jan 11 19:33 COPYING
drwxr-xr-x 18 www-data www-data  4096 Jan 11 19:34 core
-rw-r--r--  1 www-data www-data  4979 Jan 11 19:34 cron.php
drwxr-xr-x  2 www-data www-data  4096 Jan  8 22:54 data
-rw-r--r--  1 www-data www-data  4076 Jan 16 00:59 .htaccess
-rw-r--r--  1 www-data www-data   156 Jan 11 19:34 index.html
-rw-r--r--  1 www-data www-data  3172 Jan 11 19:33 index.php
drwxr-xr-x  6 www-data www-data  4096 Jan 11 19:34 lib
-rw-r--r--  1 www-data www-data   283 Jan 11 19:33 occ
drwxr-xr-x  2 www-data www-data  4096 Jan 11 19:34 ocm-provider
drwxr-xr-x  2 www-data www-data  4096 Jan 11 19:34 ocs
drwxr-xr-x  2 www-data www-data  4096 Jan 11 19:34 ocs-provider
-rw-r--r--  1 www-data www-data  2951 Jan 11 19:34 public.php
-rw-r--r--  1 www-data www-data  5139 Jan 11 19:33 remote.php
drwxr-xr-x  4 www-data www-data  4096 Jan 11 19:34 resources
-rw-r--r--  1 www-data www-data    26 Jan 11 19:33 robots.txt
drwxr-xr-x 12 www-data www-data  4096 Jan 11 19:34 settings
-rw-r--r--  1 www-data www-data  2232 Jan 11 19:33 status.php
drwxr-xr-x  3 www-data www-data  4096 Jan 11 19:34 themes
drwxr-xr-x  2 www-data www-data  4096 Jan 11 19:34 updater
-rw-r--r--  1 www-data www-data   163 Jan 11 19:33 .user.ini
-rw-r--r--  1 www-data www-data   362 Jan 11 19:33 version.php

Es ist ausser dem nextcloud Ordner auch kein weiterer unter /var/www/ vorhanden. Ich kann mir so gar keinen Reim drauf machen.. ☺

ChickenLipsRfun2eat Team-Icon

Anmeldungsdatum:
6. Dezember 2009

Beiträge: 12067

Hallo!

Könnte das ein Fehler in der NAT sein? Greifst du über dynamic dns wirklich von außen zu oder rufst du aus deinem Heimnetz nur die Adresse auf?

misterunknown Team-Icon

Ehemalige
Avatar von misterunknown

Anmeldungsdatum:
28. Oktober 2009

Beiträge: 4403

Wohnort: Sachsen

Ich vermute, dass dein Umleitungsziel mit %{SERVER_NAME} nicht glücklich ist. Nimm lieber %{HTTP_HOST}.

In meinen Umgebungen sieht das so aus:

<VirtualHost *:80>
        ServerName example.org

        DocumentRoot /var/www/html

        RewriteEngine on
        RewriteCond %{REQUEST_URI} !^/.well-known
        RewriteRule (.*) https://%{HTTP_HOST}$1 [L,R=302]
</VirtualHost>

Normalerweise hab ich für einen reinen Umleitungs-VHost gar kein DocumentRoot gesetzt, sondern habe einen globalen LetsEncrypt-Alias:

/etc/apache2/conf-enabled/letsencrypt.conf:

    Alias /.well-known /var/www/letsencrypt/.well-known

    <Directory /var/www/letsencrypt/.well-known>
            AllowOverride None
            Require all granted
    </Directory
Antworten |