Apache2 Reverse Proxy Rewrite help

smdion

Limp Gawd
Joined
May 30, 2003
Messages
447
Right now I have my unraid server behind my proxy so I only have port 80 open to the world. The downfall is my unraid is a www.domain.com/main, www.domain.com/shares and so on. I want to move it to www.domain.com/unraid/main and www.domain.com/unraid/shares. I have dug through the man pages but my knowledge on rewrite is lacking to decipher them.


Current snippet from default.

Code:
<Location /Main>
        ProxyPass http://IPADDRESS:8008/Main
        ProxyPassReverse http://IPADDRESS:8008/Main
</Location>

I have rewriteengine on at the beginning of my default file.
 
Last edited:
It's not really a rewrite thing. Are you sure you have mod_proxy installed and active?
 
I do have mod proxy installed. It works great at the domain.com/main I just want it to work at domain.com/unraid/main
 
I am not sure why you are specifying a location of '/Main' then. You should be specifying '/unraid'

Code:
<Location /unraid/Main>
        ProxyPass http://IPADDRESS:8008/Main
        ProxyPassReverse http://IPADDRESS:8008/Main
</Location>
 
Code:
<Location /unraid>
        ProxyPass http://IPADDRESS:8008/
        ProxyPassReverse http://IPADDRESS:8008/
</Location>
<Location /Main>
        ProxyPass http://IPADDRESS:8008/Main
        ProxyPassReverse http://IPADDRESS:8008/Main
</Location>
<Location /plugins>
        ProxyPass http://IPADDRESS:8008/plugins
        ProxyPassReverse http://IPADDRESS:8008/plugins
</Location>
<Location /Shares>
        ProxyPass http://IPADDRESS:8008/Shares
        ProxyPassReverse http://IPADDRESS:8008/Shares
</Location>
<Location /Users>
        ProxyPass http://IPADDRESS:8008/Users
        ProxyPassReverse http://IPADDRESS:8008/Users
</Location>
<Location /Settings>
        ProxyPass http://IPADDRESS:8008/Settings
        ProxyPassReverse http://IPADDRESS:8008/Settings
</Location>
<Location /Utils>
        ProxyPass http://IPADDRESS:8008/Utils
        ProxyPassReverse http://IPADDRESS:8008/Utils
</Location>
<Location /Health>
        ProxyPass http://IPADDRESS:8008/Health
        ProxyPassReverse http://IPADDRESS:8008/Health
</Location>
<Location /Stats>
        ProxyPass http://IPADDRESS:8008/Stats
        ProxyPassReverse http://IPADDRESS:8008/Stats
</Location>

Is the full default for that site, but the links are hard coded to go to domain.com/main or domain.com/health. I want the proxy when it sees domain.com/main to rewrite it to domain.com/unraid/main
 
Ok, so the only proxy entry you should need is the '/unraid' one.

Code:
<Location /unraid>
        ProxyPass http://IPADDRESS:8008/
        ProxyPassReverse http://IPADDRESS:8008/
</Location>

The proxy code is just making an alias of '/unraid', so the '/unraid' path goes to your internal server. All other paths of /unraid/Main, /unraid/Shares, etc should now be valid paths.

Now you just need mod_rewrite to handle the hard coded paths for you. You may be able to do this with Apache's 'Alias', but I am not sure. Here is the typical code from an .htaccess.

Code:
Options +FollowSymLinks
RewriteEngine On
ReWriteRule ^/Main/(.*)$ /unraid/Main/$1 [R,L]

I haven't tested it, but it may give you a starting place. Another option may be to use the 'Redirect' option.

Code:
Redirect 301 /Main /unraid/Main

But you are correct, the documentation for several of these items isn't the best, so I have found that I tend to play with things for a while until I get it to work properly.
 
Thanks for the help. One last question. I also have ProxyPasses for other services running on different IPs/Ports in the same default document. How to I put in the rewrite without having it effect those?
 
May I suggest using mod_proxy_html instead of mod_rewrite? It should be better suited for this situation
 
You may, and how would I go about implementing that ;)

I've written a blog post about it here, but it's more about using reverse proxying for development purposes.
http://www.benjaminhorn.se/post/apache-reverse-proxy/

Here's a gist example of a virtualhost-config
https://gist.github.com/beije/5689935

So the only thing you'd basically need to do is add this to your <location />:
Code:
    # Ouput html from proxy filter
    SetOutputFilter proxy-html

    # Overwrite html, exchange urls with proxied ones
    ProxyHTMLExtended On
    ProxyHTMLURLMap http://hosts.domain.dev  http://10.0.0.10

You might need to copy more stuff from the above gist, but I really don't think you'll need mod_rewrite at all on the proxy server :)
 
Thanks!

I ended up using a combination of both


Code:
        ProxyPass http://10.10.10.11:8008/Shares
        ProxyPassReverse http://10.10.10.11:8008/Shares

        Redirect 301 /Shares /unraid/Shares

        # Ouput html from proxy filter
        SetOutputFilter proxy-html

        # Overwrite html, exchange urls with proxied ones
        ProxyHTMLExtended On
        ProxyHTMLURLMap http://www.domain.com/unraid/Shares  http://10.10.10.10.11:8008/Shares
 
Last edited:
OK. Part 2 of this request.

My unraid server has a file at 10.10.10.11:8008/update.htm that passes thru all the commands to restart server, change anything, etc...

So its requesting thru domain.com/update.htm. I don't want to pass all root files thru to 10.10.10.11. Is there a proxy command that I can say when www.domain.com/update.htm is requested pass thru to 10.10.10.11:8008/update.htm?
 
Back
Top