I have multiple web applications running on their own http server, e.g. a ruby/rails application on port 8080 and a python/cherrypy application on 8081.

Is it possible to make these transparently available via single port address? Perhaps by adding a third http server that transforms all requests (e.g. http://localhost/app1 & http://localhost/app2). My platform of choice is Linux

  • a load balancer perhaps? Check out nginx, pound and haproxy.
    – 3molo
    Feb 8 '11 at 19:29

What you're looking for is called "reverse proxy". There are many web servers that have this capability, including Apache httpd, lighttpd, and nginx, as well as more stripped-down web servers designed solely for reverse proxying.

Since Apache is the most likely to be available to you and/or easiest to deploy, this snippet of code to be included in the relevant section of your Apache config files should give you the minimal configuration for what you need, assuming you have mod_proxy_http installed and enabled:

# ... [snip] ...
<VirtualHost *:80>
# ... [snip] ...

# This line prevents mod_proxy from acting as a forward proxy
# Yes it looks silly, but it's correct for reverse proxy configurations
ProxyRequests Off

# Rails app on port 8080
ProxyPass /app1 http://localhost:8080
ProxyPassReverse /app1 http://localhost:8080

# CherryPy app on port 8081
ProxyPass /app2 http://localhost:8081
ProxyPassReverse /app2 http://localhost:8081

# ... [snip] ...

Update: here are some links to (sometimes dense) documentation for various servers:

Word to the Wise

Also consider that with reverse-proxy the back-end applications will no longer be receiving requests from the IP of the client initiating the request. Instead, all requests will appear to come from localhost ( So any client IP-related logic will stop functioning. If your application needs this request metadata, you will need to follow a procedure dependent on your reverse proxy HTTP server.

In Apache, mod_proxy automatically adds an X-Forwarded-For header to the request whose value is the IP address of the request that came into Apache (or a list of IPs that have forwarded the request, if you have a chain of several reverse proxies). For Nginx, I believe you may have to instruct the server to send such a header (details are in the link above).

If your back-end application cares about the Host: header from the original client request, you'll need to modify that code to look for (in Apache) the X-Forwarded-Host header as well.

  • Only knowing the name of what I was looking for would have helped a lot, but appending an Apache configuration snippet is even more helpful. Thanks a lot!
    – ckuijjer
    Feb 8 '11 at 19:40

It's called a Reverse Proxy. You can do it with Apache as well as other web servers. There are also dedicated proxy servers that you could use as well.


Yes you can do something like this in APACHE using mod_jk

Details here: http://www.ruby-forum.com/topic/211503

Basically what happens is APACHE is used a a 'router/proxy' for your ruby traffic. You don't need any new servers / ips that way. Keep in mind that you are THAN dependent on Apache to funnel traffic to your app.

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.