Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Jetty running on port 8080 as a reverse proxy behind an Apache2 instance running on 80. Here is the configuration:

<VirtualHost *:80>
ServerName  default
##########################
# DocumentRoot
DocumentRoot /var/www
<Directory /var/www/>
  Options FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
</Directory>

##########################
# Error Handling
ErrorDocument 503 /errors/503.html
ErrorDocument 404 /errors/404.html

##########################
# Proxy
ProxyRequests Off
<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>
ProxyPass /errors !
ProxyPass / http://localhost:8080/
ProxyPreserveHost On
ProxyStatus On
</VirtualHost>

Basically any request which does not match the other configured virtual hosts ends up matching this one. In other words, anything not matching an apache virtual host will end up being proxied to Jetty.

Jetty is running a web app which responds differently based on the Host found in the request header. In other words, both foo.com and bar.com can be pointed to this web app, and it will show a fooish page or a barish page depending on the Host you requested.

I need to expose this functionality through the proxy, and I'd like to do it by having mod_proxy convert calls to this:

http://myapp.acme.com/foo.com/index.html

to

http://foo.com/index.html

before passing it on to Jetty so that the web app functions correctly based on the requested host. With my current configuration, requesting the first URL passes on:

Host: myapp.acme.com
GET /foo.com/index.html

but I need it to pass on

Host: foo.com
GET /index.html
share|improve this question

1 Answer 1

up vote 0 down vote accepted

This, or something like it, might work:

ProxyPreserveHost Off # default is Off, just making the point
ProxyRemote * http://localhost:8080/
RewriteEngine On
RewriteRule ^/([^/]+)/(.*) http://$1/$2 [P]

ProxyRemote means that this proxy (the one on port 80) will forward requests on via the specified proxy. If this doesn't make sense, shout! I'm out of time for the moment. The proxy docs should help.

share|improve this answer
    
http://$2/$1 should be http://$1/$2, but that does work, thank you. –  rcampbell Jan 2 '10 at 13:28
    
Good spot. Fixed. Glad it worked. –  markdrayton Jan 3 '10 at 8:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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