29.11.2014

Domainweiterleitung mit RewriteRule auf einer Synology DiskStation

-

Dieser Artikel ist obsolet:

Mit der Aktualisierung der DiskStation Firmware auf DSM 6 funktioniert die hier beschriebene Konfiguration der Hosts in Apache im Synologysystem nicht mehr. Eine Alternative ist mir leider nicht bekannt. (09.05.2016)

-

In einer .htaccess-Datei können standardmäßig keine Umleitungen auf Dateisystempfade definiert werden.

AllowAnyURI
When RewriteRule is used in VirtualHost or server context with version 2.2.22 or later of httpd, mod_rewrite will only process the rewrite rules if the request URI is a URL-path. This avoids some security issues where particular rules could allow "surprising" pattern expansions (see CVE-2011-3368 and CVE-2011-4317). To lift the restriction on matching a URL-path, the AllowAnyURI option can be enabled, and mod_rewrite will apply the rule set to any request URI string, regardless of whether that string matches the URL-path grammar required by the HTTP specification.
Available in Apache HTTP Server 2.4.3 and later.
Security Warning
Enabling this option will make the server vulnerable to security issues if used with rewrite rules which are not carefully authored. It is strongly recommended that this option is not used. In particular, beware of input strings containing the '@' character which could change the interpretation of the transformed URI, as per the above CVE names.
http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

Über SSH kann in der SynologyDS eine Weiterleitung in der Konfigurationsdatei für die Virtuellen Hosts eingerichtet werden.

Synology> vi /etc/httpd/sites-enabled-user/httpd-ssl-vhost.conf-user

(Dies betrifft nur HTTPS-Seiten. Für unverschlüsselte Seiten ist (zusätzlich) die Datei httpd-vhost.conf-user zu editieren.)

Im Eintrag des betroffenen Virtuellen Hosts ist die RewriteRule zu ergänzen und ggf. die RewriteEngine zu aktivieren.

<VirtualHost *:443>
ServerName www.exampledomain.de
DocumentRoot "/var/services/web/examplefolder"
# ...
RewriteEngine On
RewriteRule ^/virtualsubfolder(.*) "/var/services/web/virtualsubfolder$1" [L]
</VirtualHost>

Im Anschluss muss der Apache-Server neu gestartet werden.

Synology> synoservicectl --restart httpd-user

Andere RewriteRules können hier natürlich auch gesetzt werden. Zum Beispiel eine Proxy-Umleitung auf einen Backend-Server im lokalen Netzwerk:

SSLProxyEngine On
RewriteRule ^/proxysubfolder https://[target-ip]:[port]/proxytarget [P]
ProxyPassReverse /proxysubfolder/ https://[target-ip]/

Wenn das Proxy-Ziel über SSL/https erreicht werden soll, muss ggf. SSLProxyEngine On gesetzt werden.