14

Currently, we have an IIS server as our primary web server. We are implementing an Apache server in its place, but still need to have the IIS server accessible. Typically, this is a simple thing, because Apache2 can proxy a subdomain to this server.

Our problem, however, is this: we are using dotnetCharting on the IIS server, and the licensing is tied to the domain name. In order to get dotnetCharting to work, another license will have to be purchased.

My question is, can Apache2 proxy a subdirectory? For example, can 'www.example.com/subdir' point to the IIS server? It seems like it shouldn't be impossible, but I can't seem to find a solution for this.

20

Sure. But be careful; a lot of web applications aren't designed well for having their URL path change. Is the application used in a sub-directory currently?

# You'll probably want this to maintain the host mapping in IIS
ProxyPreserveHost On
# Swap in the IP address or internal host name of your IIS server:
ProxyPass /subdir/ http://192.0.2.100/subdir/

Or, if you're altering the URL path, keeping in mind that a lot of applications will have problems with this, due to absolute paths for resources (CSS, javascript, images):

ProxyPass /subdir/ http://192.0.2.100/
ProxyPassReverse /subdir/ http://192.0.2.100/
3
  • Perfect! That did the trick in my test environment. Right now, internally, you can enter the server's IP address and use our internal proxy to get to the server, and everything (except dotnetcharting) works perfectly, so I don't expect the application to fail when we proxy it with this method. Much appreciated!
    – SuperJer
    Sep 17 '12 at 16:40
  • 1
    I had to leave off the trailing / from subdir (like this: /subdir). Otherwise if domain.com/subdir results in an application error (500). It would proxy correctly if the slash was included (domain.com/subdir/), but that's not the effect I was looking for. Jan 5 '16 at 21:49
  • I didnt quite get what ProxyPreserveHost does? I tried reading in the documentation of apache but still couldnt be sure. So what happens if I set this and i have localserver.com/subdir/ forward the request to remoteserver.com/subdir but that has remoteserver.com/subdir downloading other js,css,html files, the problem I am having is that it is trying to download from localserver.com and those files are only present on remoteserver
    – Murilo
    Aug 18 '20 at 4:47
3

the final slash on the end is NOT mandatory. I had it setup like this

ProxyPass /dir http://exmpale.com/dir/ 

ProxyPassReverse /dir http://exmpale.com/dir/ 

and the the top level worked but eveyrything in subdirs beneath the main one did not.

I changed it to this and everything worked.

Thanks for the misinformation!!!

ProxyPass /dir http://exmpale.com/dir

ProxyPassReverse /dir http://exmpale.com/dir
1
  • 2
    Why do people downvote this? It was exactly the problem I had. You have to either end both urls with a slash or leave both urls without a slash.... atleast for me it helped when it came to sub directories ;)
    – Jannik
    Sep 29 '18 at 22:30
2

Sure.

  1. Enable mod_proxy mod_proxy_http
  2. set the following instruction in your Apache VHost

    ProxyPass /subdir http://iis.server/.../
    ProxyPassReverse /subdir http://iis.server/.../
    

Note the final "/" is mandatory.

For moreinformation: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

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.