7

Having an application running on port 10001 I would like to have a reverse proxy to serve it on hostname/ds . The only problem is that there are hard linked scripts to /scripts/...

That means hostname/ds/ shall get me to localhost:10001/ and hostname/scripts should first rewrite the request url to hostname/ds/scripts/*.

My configuration:

<VirtualHost *:80>
RewriteEngine on
RewriteRule /^scripts/(.*)$ /ds/scripts/$1 [L,PT]   

ProxyPass /ds/ http://127.0.0.1:10001/
ProxyPassReverse /ds/ http://127.0.0.1:10001/

</VirtualHost>

It does not work: hostname/scripts/ gets a 404. while hostname/ds/scripts/ gets the right answer by the application.

According to https://stackoverflow.com/questions/9003358/apache-rewrite-then-proxy-pass PT should work. What am I doing wrong?

6

you have a typo in your pattern, try ^/ instead of /^ (latter will never match)

5

You can also do this by simply adding a second ProxyPass to match /scripts, like so:

<VirtualHost *:80>
    ProxyPass /scripts/ http://127.0.0.1:10001/
    ProxyPassReverse /scripts/ http://127.0.0.1:10001/

    ProxyPass /ds/ http://127.0.0.1:10001/
    ProxyPassReverse /ds/ http://127.0.0.1:10001/
</VirtualHost>
4

I know this thread is already solved but it seems that you are trying to use ProxyPass to reach the web interface of a Synology DiskStation. For anyone who faced the same problem, with the latest version (DSM 5.1-5004 Update 2) I had to use the following config with the following RewriteRules:

<VirtualHost *:80>
    RewriteRule ^/scripts/(.*)$ /ds/scripts/$1 [L,PT]
    RewriteRule ^/webfm/(.*)$ /ds/webfm/$1 [L,PT]
    RewriteRule ^/webapi/(.*)$ /ds/webapi/$1 [L,PT]
    RewriteRule ^/webman/(.*)$ /ds/webman/$1 [L,PT]

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia Off
    ProxyPass /ds/ http://192.168.1.10:5001/
    ProxyPassReverse /ds/ http://127.0.0.1:5001/
</VirtualHost>

This obviously is subjected to change with newer versions of DS. I found using FireBug very helpful when searching for the folders that DS requests (that needed to be redirected).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.