Has anyone had any success running two different web servers -- such as Apache and CherryPy -- alongside each other on the same machine? I am experimenting with other web servers right now, and I'd like to see if I can do my experiments while keeping my other sites up and running. You could say that this isn't so much a specific-software question as it is a general networking question.

  • I know it's possible to run two web servers on different ports; but is there any way to configure them so that they can run on the same port (ie, they both run on port 80)?
  • The web servers would not be serving files from the same domains. For example, Apache might serve up documents from foo.domain.com, and the other web server would serve from bar.domain.com.

I do know that this is not an ideal configuration. I'd just like to see if it can be done before I go sprinting down the rabbit hole. :)

Accepted Answer

You can't have two processes bound to the same port on the same IP address. You can add another IP address to the box and have each server listen on one.

Another option is to proxy pass one server to the other. With Apache, you could do something like:

NameVirtualHost *
<virtualhost *>
  ServerName other.site.com

  # assumes CherryPy listens on port 8080
  ProxyPass / <>
  ProxyPassReverse / <>

That's a pretty quick example, but you can always check the ProxyPass documentation. Remember though, the application being proxyed to will get in it's logs instead of the requester's IP address. Some web servers (apache does with mod_rpaf) can substitute the X-Forwarded-For header in place of the wrong IP address. Possibly CherryPy has this?

Written by Gary Richardson
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki