Update
Gemäss diversen Problemen mit der Weiterleitung via /dsm habe ich den Beitrag abgeändert, so dass eine Subdomain verwendet wird z.B https://ds.domain.tld
Damit sollte es auch keine Konflikte mit den Apache Konfigurationen für PhotoStation etc. mehr geben.
Wer mit eingeschränkten Möglichkeiten im Internet unterwegs ist (z.B vom Firmennetzwerk aus oder Internetcafe) bei dem die Mangement Ports der Synology Diskstation (http:5000 und https:5001) gesperrt sind aber dennoch auf seine Diskstation zugreifen möchte kann dies via Reverse Proxy einfach bewerkstelligen. Dazu wird der eingebaute Apache Webserver in Kombination mit dem Modul mod_proxy verwendet. Auf diese Weise können alle Dienste, welche einen anderen Port als http/80 oder https/443 verwenden angeboten werden.
Ich habe ein ganz einfaches Script geschriben, dass die nötigen Schritte vornimmt.
Damit der Reverse Proxy eingerichtet werden kann muss die Webstation aktiviert sein.
Danach via SSH auf die Diskstation einloggen und folgendes in der Console ausführen
wget -O install_reverseProxy.sh https://www.irbe.ch/wp-content/uploads/scripts/Synology_reverseProxy.sh chmod +x install_reverseProxy.sh nano install_reverseProxy.sh
Bei der Variable URL die eigene eintragen
Nano Editor schliessen mit Ctrl + X, danach y drücken zum überschreiben und mit Enter den Pfad bestätigen
und Script starten mit
./install_reverseProxy.sh rm install_reverseProxy.sh
Source Code des Scripts
#!/bin/sh #You must change this Variable to suit your Hostname #---------------------------------------------------- URL="ds.irbe.ch" #The main URL of the site #---------------------------------------------------- #Normally you do not have to change these variables ReverseProxyFile="/usr/local/etc/reverse_proxy.conf" #Path to the ReverseProxyFile config="/etc/httpd/sites-enabled-user/httpd-ssl-vhost.conf-user" apache="httpd -k" #Create the Reverse Proxy File echo " <IfModule !proxy_module> LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_http_module modules/mod_proxy_http.so </IfModule> NameVirtualHost *:443 <VirtualHost *:443> ServerName $URL SSLEngine On SSLProxyEngine On ProxyRequests Off ProxyVia Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / https://localhost:5001/ ProxyPassReverse / https://localhost:5001/ </VirtualHost> " > $ReverseProxyFile #Include the Reverse Proxy File in the main apache config file echo "include $ReverseProxyFile" >> $config #Restart the apache service $apache restart
Nun kann der Diskstation Manager via https://ds.domain.tld aufgerufen werden
Hi,
funktioniert soweit. Aber nur über die Domain (https://domain.tld). Wenn ich https://domain.tld/dsm eingebe, bekomme ich nur eine Fehlermeldung.
Kann es sein dass es so lauten müsste:
ProxyPass /dsm https://localhost:5001/
ProxyPassReverse /dsm https://localhost:5001/
anstatt
ProxyPass / https://localhost:5001/
ProxyPassReverse / https://localhost:5001/
Gruß Bernd
Du hast natürlich recht, da ist mir ein Schreibfehler unterlaufen.
Besten Dank für die Info. Habs angepasst
Hi,
wenn ich das richtig verstehe, könnte man das auch weiterspinnen und auch andere Seiten, die lokal auf der DSM laufen so anzeigen lassen (z.B tvheadend, wiki, etc…). Das klappt dann auch soweit, wenn ich in der Datei /usr/local/etc/reverse_proxy.conf die entsprechenden Einträge hinzufüge.
Wenn ich aber auf einen anderen Server innerhalb meines Netzwerkes so zugreifen möchte (ich gebe anstatt localhost die entsprechende IP Adresse ein) bekomme ich nur von der DSM eine Fehlermeldung.
Hättest Du da eventuell einen Tip für mich?
Gruß Bernd
@bernd
das würde mich auch sehr interessieren. ich habe intern diverse virtual servers mit web applikationen darauf und diese haben teilweise anderer ports teilweise auch die gleichen.
ich würde gerne die ports verschwinden lassen wenn eine entsprechende subdomain aufgerufen wird.
aktuell habe ich das ganze so gelöst.
example:
domain = app.mydomain.com
router = 192.168.1.1
synology’s ip = 192.168.1.2
app machine = 192.168.1.13
app lan url = 192.168.1.13:8100
app port = 8100
ich habe ein virtual host unter web service im synology angelegt der den traffic von port 80 auf einen ordner in ordner web leitet und dort habe ich eine htaccess datei mit folgendem inhalt
RewriteEngine on
RewriteRule (.*) http://app.mydomain.com:8100/$1 [R=301,L]
wenn also der user im browser app.mydomain.com eingibt wird er weitergeleitet auf app.mydomain.com:8100 und kann die applikation nützen.
ich würde aber gerne das der port nicht auftaucht im browser. somit könnte habe ich den gleichen gedanken wie du beschrieben hast. vielleicht hat ja Phil eine idee
Greetings,
First; Thank you for posting this tutorial (even though I had to use Google Translate a bit).
I have only been partially successful in getting this to work; The redirect to https://domainname.tld/dsm to https://domainname.tld:5001/webman/index.cgi seems to work fine. But the DSM does not load. The webpage is just white. This makes me think that there are some options that I have forgotton.
I have tried ReverseProxy with other services running on my DSM, and it work flawlessly. It is just the DSM that does not work
Any suggestions?
Maybe it’s not a server issue. Have you tried different webbrowsers?
I’ll try a different browser and do a little bit of more testing tomorrow.
I had to disable the Reverse Proxy all toghether. I found out it interferes with ownCloud v.6. (The login page (i.e. https://domainname.tld/owncloud/ goes into a redirect loop it seems).
You would not know enything about this, would you? As soon as I #’ed out the reverse_proxy.conf, ownCloud started working again.
An update; No – it is not browser specific. Same thing happens in multiple browsers.
hmm ok, you should enable the access logfile if you haven’t already and see whats happening:
cd /usr/syno/apache/conf
cp httpd.conf-user httpd.conf-user-backup
vi httpd.conf-user
CustomLog /volume1/web/log/access.log combined
cd /volume1/web
mkdir log
/usr/syno/etc/rc.d/S97apache-user.sh restart
I tried the errorlog when NOT including the reverse-proxy, and nothing showed up (as it should).
When I included the reverse-proxy, i get the following errors. One is related to Mozilla Sync, one to the Windows Sync client (I think) and one to the web-based login (I think). I have modified the output a bit (masking IP’s and usernames, etc:)
“GET /owncloud/remote.php/mozilla_sync/1.1/XXXXXXX/info/collections HTTP/1.1” 500 20 “-” “Firefox/27.0.1 FxSync/1.29.0.20140212131424.desktop”
“GET /owncloud/ HTTP/1.1” 500 20 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0”
“PROPFIND /owncloud/remote.php/webdav/ HTTP/1.1” 500 20 “-” “Mozilla/5.0 (Windows) mirall/1.5.0”
Other than this, I am at a loss why ownCloud (and only that) seems to be effected by the reverse-proxy.
hmm very strange.
I have no experience with owncloud.
Maybe you could use Synology’s CloudStation. This works for me perfectly
ownCloud is so much more versatile then CloudStation; it handles and syncs my files, calendar, contacts, tasks and sync my Mozilla Settings and is much more cross-platform friendly, open-source and is actively developed. So I’d rather the Reverse Proxy not working then having the reverse proxy work and use cloudstation 🙂
Ah ok, maybe I’ll give it a try someday if I have the time 😉
Now that DSM 5 Final is out, your scrips need updating. They have completely changed default directories for Apache :/ … Just a heads up 🙂
Hi Phil,
ich komme noch mal auf den letzten Kommentar von Òyvind zurück. DSM 5 ist draußen, da klappt Dein Script nicht mehr. Die Pfade haben sich komplett geändert. Bin schon auf der Suche nach einer Lösung und bin hierauf gestoßen:
http://primalcortex.wordpress.com/2014/03/14/synology-dsm-5-web-station-and-virtual-sites-for-filestation/
Habe es aber leider nicht hinbekommen. Anscheinend bin ich zu blöd, hehe. Wenn Du mal Zeit hast kannst Du Dir das ja zu gemühte führen. Eventuell bringt Dir die Seite was.
Gruß Benuk
So ich hab das Script angepasst schau mal ob es nun funktioniert.
Geändert hat sich folgendes:
line 10: config=”/etc/httpd/sites-enabled-user/httpd-vhost.conf-user”
line 11: apache=”httpd -k”
Hi Phil,
werde ich heute Abend von zuhause aus testen. Gebe dann Bescheid ob alles funktioniert.
Cool dass es so schnell geklappt hat!
Gruß Benuk
Hi,
hab das versucht, bekomme aber eine Fehlermeldung bezüglich der ssl Einträge.
Diese müssen in einem Tag stehen:
SSLEngine On
SSLProxyEngine On
Dann ist de Fehlermeldung weg.
Funktionieren tut es dennoch nicht. Ich denke es hat mit DSM 5 zu tun. Mit der 4er Version lief alles super. Habe bei mir die aktuellste Version drauf (DSM 5.0-4493).
Kannst Du mir einen Tip geben, wie ich das ganze mit Sub-Domains einrichten kann?
Habe die Möglichkeit welche zu nutzen, z.B.: http://www.dsm.irbe.ch
Gruß Bernd
Ups,
da wurden die Tags verschluckt! Die Anführungszeichen müssen durch “größer gleich” und “kleiner gleich” Zeichen ersetzt werden:
“IfDefine SSL”
SSLEngine On
SSLProxyEngine On
“/IfDefine”
Gruß Bernd
Hi Bernd
Ist bei dir evtl. das SSL Modul in Apache nicht geladen?
füge mal noch die nachfolgenden 3 Zeilen zuoberst in der reverse_proxy.conf hinzu:
(IfModule !ssl_module)
LoadModule ssl_module modules/mod_ssl.so
(/IfModule)
Die runden Klammern durch Eckige ersetzten! (<) (>)
Hallo zusammen,
die Line 10 müsste von
config=”/etc/httpd/sites-enabled-user/httpd-vhost.conf-user”
auf
config=‚Äù/etc/httpd/sites-enabled-user/httpd-ssl-vhost.conf-user”
geändert werden, da hier Port 443 umgeleitet werden soll und nicht Port 80.
Nachdem mein Reverse Proxy nach dem Upgrade auf DSM 5 auch nicht mehr funktioniet hat, funktioniert er nach dem Umzug nach httpd-ssl-vhost.conf-user wieder perfekt.
Ich hoffe, die Info hilft weiter.
LG Gerold
Danke Gerold für den Hinweis ich habs im Post angepasst
Hi,
@ Phil: Danke für Deine Mühe! Das war es leider nicht.
@ Gerold: vielen Dank!!! Das wars gewesen. Nachdem ich das angepasst habe, funktioniert wieder alles!!!!
Hier noch mal Danke an Dich Phil!
Finde es Super, dass Du aktiv versuchst bei Problemen zu helfen!
Gruß Bernd
Vielen Dank für das tut. Konfig nach deinen Angaben. Erhalte beim Aufruf domain.com/dsm die Meldung “Es tut uns Leid, die von Ihnen gesuchte Seite konnte nicht gefunden werden.” bei https://domail.com/dsm “Verbindung fehlgeschlagen” (DSM 5.0-4493 Update 3). Danke fürs Feedback.
Vielen Dank für die Anleitung.
Leider funktioniert es bei mir nicht ganz.
Wenn ich auf “https://servername.myds.me/dsm” gehe, dann werde ich auf “https://servername.myds.me/dsmwebman/index.cgi” weitergeleitet (es fehlt ein “/”).
Gehe ich direkt auf “https://servername.myds.me/dsm/webman/index.cgi”, dann sehe ich im Quelltext zwar, dass der DSM geladen wird, aber ein paar Ressourcen werden nicht geladen, sodass er nicht angezeigt werden kann.
Hat jemand eine Idee, woran das liegen könnte?
Das ist nun schon ca. das 3x dass die angepassten vHosts / SSL / Reverse Proxy nach dem Update (aktuell: 5.0-4493 Update 4) nicht funktionieren. SYNOLOGY!!!!!
Hallo zusammen,
ich wollte auch den DSM per Reverse Proxy extern erreichbar machen aber nicht “/” weiterleiten, sondern “/dsm/”. Hatte das gleiche Problem wie Òyvind, die Seite blieb einfach leer. Habe dann mal mit Tamperdata die Requests verfolgt und in den CGIs sind Links zu weiteren Ressourcen fest verdrahtet und damit fehlt in der URI jeweils das “/dsm/”. Es sind nur drei Pfade, daher habe ich das ebenfalls weitergeleitet und damit geht es. Wenn jemand weiß, wie man das geschickter mit Rewrite Rules macht, immer her damit. Falls man beim Tippen den “/” am Ende vergisst, habe ich eine Rewrite Rule gefunden, die den anhängt.
# Add a trailing slash if necessary
RewriteCond %{REQUEST_URI} ^/[a-z]+$
RewriteRule ^(.*)$ $1/ [R=301,L]
ProxyPass /dsm/ https://localhost:5001/
ProxyPassReverse /dsm/ https://localhost:5001/
ProxyPass /scripts/ https://localhost:5001/scripts/
ProxyPassReverse /scripts/ https://localhost:5001/scripts/
ProxyPass /webfm/ https://localhost:5001/webfm/
ProxyPassReverse /webfm/ https://localhost:5001/webfm/
ProxyPass /webapi/ https://localhost:5001/webapi/
ProxyPassReverse /webapi/ https://localhost:5001/webapi/
Hallo zusammen,
ich habe in der Systemsteuerung das Anwendungsportal entdeckt, hier kann man sowas ja schon für einige Aplikationen festlegen, dass sie über ein Alias (z.B. Audiostation über https://diskstation.domain.tld/audio) zu erreichen sind. Das geht in meinem Fall ohne Portangabe, da ich an meinem Route den externen Port 443 auf die Diskstation Port 5001 umgeleitet habe. Ich habe jetzt mal eine Support-Anfrage gestellt, ob hier auch der WebDAV-Service integrierbar wäre. Allerdings habe ich so grade keine Möglichkeit, auf den Port 443 an der Diskstation (benötigt für Webstation und Photostation) zuzugreifen, von daher müsste Synology da wohl grundsätzlich was verändern…
Gruss ssab
Hallo Phil,
ich hab dein Skript erweitert und alles automatisiert. So wir der Reverseproxy bei jedem Start überprüft und erstellt gleichzeitig die Subdomains, die für die Dienste der Synology (Audiostation usw.) benötigt werden. Alle Dienste laufen auf Subdomains(audiostation.DEINEDOMAIN.de).
Man muss in dem Skript nur seine Domain eingeben und in /usr/local/etc/rc.d/ kopieren. Nicht vergessen die Datei mit den nötigen Rechten zu versehen (chmod 777 zum Bleistift). Viel Spaß damit, Gruß Michi.
#!/bin/sh
#You must change this variable to suit your hostname
#----------------------------------------------------
URL="YOURDOMAIN.DE" #The main URL of the site
#----------------------------------------------------
#Clear your browsers cache!!!
#Normally you do not have to change these variables
ReverseProxyFile="/usr/local/etc/reverse_proxy.conf" #Path to the ReverseProxyFile
UserReverseProxyFile="/usr/local/etc/user_reverse_proxy.conf"
httpconfig="/etc/httpd/sites-enabled-user/httpd-vhost.conf-user"
httpsconfig="/etc/httpd/sites-enabled-user/httpd-ssl-vhost.conf-user"
apache="httpd -k"
includeInSubdomainConfig()
{
#Forwarding the $1 subdomain to $2
mkdir /volume1/web/$1/
chmod 777 /volume1/web/$1/
echo "Redirect 301 / https://$URL/$2" > /volume1/web/$1/.htaccess
chmod 755 /volume1/web/$1/.htaccess
echo "
ServerName $1.$URL.de
DocumentRoot "/var/services/web/$1"
ErrorDocument 403 "/webdefault/sample.php?status=403"
ErrorDocument 404 "/webdefault/sample.php?status=404"
ErrorDocument 500 "/webdefault/sample.php?status=500"
" >> $httpconfig
}
addMissingSubdomains()
{
#Forwarding the dsm subdomain
if [ ! -e "/volume1/web/dsm/.htaccess" ]
then includeInSubdomainConfig dsm webman
fi
#Forwarding the audio subdomain
if [ ! -e "/volume1/web/audio/.htaccess" ]
then includeInSubdomainConfig audio audio
fi
#Forwarding the video subdomain
if [ ! -e "/volume1/web/video/.htaccess" ]
then includeInSubdomainConfig video video
fi
#Forwarding the mail subdomain
if [ ! -e "/volume1/web/mail/.htaccess" ]
then includeInSubdomainConfig mail mail
fi
#Forwarding the file subdomain
if [ ! -e "/volume1/web/file/.htaccess" ]
then includeInSubdomainConfig file file
fi
#Forwarding the note subdomain
if [ ! -e "/volume1/web/note/.htaccess" ]
then includeInSubdomainConfig note note
fi
#Forwarding the www subdomain
if [ ! -e "/volume1/web/www/.htaccess" ]
then includeInSubdomainConfig www www
fi
#Forwarding URL to blog site
if [ ! -e "/volume1/web/.htaccess" ]
then
echo "Redirect 301 / http://$URL/blog" > /volume1/web/.htaccess
chmod 755 /volume1/web/.htaccess
fi
}
includeUsers()
{
# creates proxy rules for private photostations
if [ -e "/usr/local/etc/user_reverse_proxy.conf" ]
then
rm /usr/local/etc/user_reverse_proxy.conf
fi
for USER in $(awk -F: '$6 ~ /\/home/ && $3 >= 500 {print $1}' /etc/passwd)
do
echo "ProxyPass /~$USER/photo http://localhost/~$USER/photo
ProxyPassReverse /~$USER/photo http://localhost/~$USER/photo" >> $UserReverseProxyFile
done
}
createReverseProxyFile()
{
#Create the Reverse Proxy File
echo "
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
NameVirtualHost *:443
ServerName $URL
SSLEngine On
SSLProxyEngine On
ProxyRequests Off
ProxyVia Off
Order deny,allow
Allow from all
ProxyPass /mail http://localhost/mail
ProxyPassReverse /mail http://localhost/mail" > $ReverseProxyFile
cat $UserReverseProxyFile >> $ReverseProxyFile
echo "ProxyPass /photo http://localhost/photo
ProxyPassReverse /photo http://localhost/photo
ProxyPass / https://localhost:5001/
ProxyPassReverse / https://localhost:5001/
" >> $ReverseProxyFile
}
enableReverseProxyFile()
{
#Include security modules (.htaccess) and the Reverse Proxy File in the main apache config file
echo "LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule auth_digest_module modules/mod_auth_digest.so
Include $ReverseProxyFile" >> $httpsconfig
#Restart the apache service
$apache restart
}
case $1 in
start)
# Proxy rules for private photostations
includeUsers
# Adds missing subdomains
addMissingSubdomains
# Checks if "/usr/local/etc/reverse_proxy.conf" is installed
if [ -e "/usr/local/etc/reverse_proxy.conf" ]
then
rm /usr/local/etc/reverse_proxy.conf
fi
createReverseProxyFile
# Checks if "/usr/local/etc/reverse_proxy.conf" is enabled
if grep "$ReverseProxyFile" $httpsconfig;
then
/usr/syno/bin/synologset1 sys info 0x11800000 "ReverseProxy is running"
else
enableReverseProxyFile
/usr/syno/bin/synologset1 sys info 0x11800000 "Enabled ReverseProxyFile"
fi
;;
stop)
# No need for doing anything
;;
*)
echo "Usage: $0 [start|stop]"
;;
esac
}
DANKE!
Zur Ergänzung, mit Zugriffsschutz:
AuthType Digest
AuthName “External”
AuthUserFile /volume1/etc/.htusers
Require valid-user
Zur Ergänzung, mit Photostation:
ProxyPass /photo https://localhost:443/photo
ProxyPassReverse /photo https://localhost:443/photo
ProxyPass / https://localhost:49495/
ProxyPassReverse / https://localhost:49495/