tags:

views:

448

answers:

4

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. :)

A: 

Your best bet would be putting Apache httpd in front of port 80 and relay requests meant for other servers through Apache by using modules. Most popular scenario would be Tomcat behind Apache where you'll be able to run both php and jsp applications.

I'm not familiar with CherryPy, so I can only suggest you look for an Apache module for CherryPy.

Edit: This looks promising: http://tools.cherrypy.org/wiki/BehindApache

Ishmaeel
A: 

Alternatively, to Ishmaeel's correct answer, if you have a server with 2 network cards, you could have each server answer requests on different IP addresses.

Dana the Sane
+6  A: 

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 / <http://127.0.0.1:8080/&gt;
  ProxyPassReverse / <http://127.0.0.1:8080/&gt;
</Virtualhost>

That's a pretty quick example, but you can always check the ProxyPass documentation. Remember though, the application being proxyed to will get 127.0.0.1 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?

Gary Richardson
A: 

I'm going to try Gary's answer first because it seems the least obtrusive to my current setup.

Also, I'm not sure if CherryPy does support the ability to log the actual IP address, but since I'm just playing around with it at this stage, I don't really need it just yet.

Thanks for the answers!

bigmattyh
I'm using a lighttpd setup to do essential the same as Gary's answer, and it works pretty well.The CherryPy instance doesn't get the real IP addresses, but lighttpd's access log gets all the real requests before it proxies them just as well, as far as I know.
elliot42