Jcyrss
Jcyrss

Reputation: 1800

How to use CherrPy as Web server and Bottle as Application to support multiple virtual hosts?

I have a website (which running in Amazon EC2 Instance) running Python Bottle application with CherryPy as its front end web server.

Now I need to add another website with a different domain name already registered. To reduce the cost, I want to utilize the existing website host to do that.

Obviously, virtual host is the solution.

I know Apache mod_wsgi could play the trick. But I don't want to replace CherryPy.

I've googled a a lot, there are some articles showing how to make virtual hosts on CherryPy, but they all assume Cherrypy as Web Sever + Web application, Not CherrPy as Web server and Bottle as Application.

How to use CherrPy as Web server and Bottle as Application to support multiple virtual hosts?

Upvotes: 2

Views: 981

Answers (4)

Jcyrss
Jcyrss

Reputation: 1800

jwalker's answer is pretty clear. In case any CherryPy newbie need whole script for reference, I post one below.

import cherrypy
from bottle import Bottle
import os


app1 = Bottle() 
app2 = Bottle()

@app1.route('/')
def homePage():    
    return "=========  home1 ==============="


@app2.route('/')
def homePage_2():    
    return "=========  home2 ==============="

vhost = cherrypy._cpwsgi.VirtualHost(None, 
                                     domains={
                                              'www.domain1.com': app1, 
                                              'www.domain2.com': app2,
                                             }
                                     )

cherrypy.tree.graft(vhost) 

cherrypy.config.update({
                        'server.socket_host': '192.168.1.4',
                        'server.socket_port': 80,
                      })
cherrypy.engine.start()
cherrypy.engine.block()

you could make www.domain1.com and www.domain1.com point to one IP adress of you server, so it servers for 2 domain in one Web Server.

Upvotes: 0

Victor Palade
Victor Palade

Reputation: 190

Another idea would be to use Nginx (http://wiki.nginx.org/Main) with uWsgi(http://projects.unbit.it/uwsgi/) & (uWsgi-python) plug-in

uWsgi has a module named emperor that you can link vhosts(vassals) in, sort of.

i'm a newbie at this myself, so not necessarily an answer but rather a suggestion to check it out. just a heads up, uWsgi and Nginx can be a hassle to get it to work, depending on your linux distro. Does work nicely with bottle, tested it myself. hope it helps

Upvotes: 0

jwalker
jwalker

Reputation: 2009

As you mentioned, use VirtualHost. In the example cherrypy.Application instances are used, but any WSGI callable (e. g. Bottle app) will do.

Upvotes: 1

Tommaso Barbugli
Tommaso Barbugli

Reputation: 12031

perhaps you can simply put nginx as reverse proxy and configure it to send the traffic to the two domains to the right upstream (the cherryPy webserver).

Upvotes: 0

Related Questions