steering subdomains to different cherrypy apps

345 views
Skip to first unread message

Gustaf Nilsson

unread,
Mar 19, 2012, 8:23:14 AM3/19/12
to cherrypy-users
Hi
Im running a home server for some web apps im developing and just like
i can have different cherrypy's listening on different ports, is it
possible to have them listen to the same port but different
subdomains? (some clients with firewalls have problems accessing other
ports than 80)

thanks
Gusty

Tim Roberts

unread,
Mar 19, 2012, 2:41:43 PM3/19/12
to cherryp...@googlegroups.com

Only one application at a time can listen to a TCP port.

You can certainly run a web server as a front end (like Apache, or one
of the lightweight web servers like Xitami or lighttpd), and have them
allocate your subdomain requests out to different ports.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Jacob Wan

unread,
Mar 19, 2012, 3:30:13 PM3/19/12
to cherryp...@googlegroups.com
On Windows, IIS can do this as well. See
http://blogs.iis.net/wonyoo/archive/2008/07/09/application-request-routing-arr-as-a-reverse-proxy.aspx.

If your various apps can somehow be assembled into one root object,
you could also look into using the VirtualHost dispatcher. See
http://tools.cherrypy.org/wiki/VirtualHosts.

Jacob

> --
> You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
> To post to this group, send email to cherryp...@googlegroups.com.
> To unsubscribe from this group, send email to cherrypy-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en.
>

Anders Langworthy

unread,
Mar 19, 2012, 3:59:20 PM3/19/12
to cherryp...@googlegroups.com

The above is generally what I do. I have the varios CP instances
listening on localhost:n, localhost:n+1 etc and then just filter the
requests by Host using Nginx. This doubles as a nice way to keep the CP
instances from needing superuser permissions and leaves any logic about
the actual URL where the apps can be found out of the app code, which is
(IMHO) as it should be.

--
Anders Langworthy
PGP Key -> AC8C B93A C0AF 1439 A21D 9293 B774 A51E AA1F 608A

Sylvain Hellegouarch

unread,
Mar 19, 2012, 4:07:40 PM3/19/12
to cherryp...@googlegroups.com
Well only one single server can bind to a given port on a given interface indeed but since CherryPy supports virtual hosting, you can serve several applications with different sub-domains in one single CherryPy server without having to resort to a reverse proxy.

For instance:
https://bitbucket.org/Lawouach/cherrypy-recipes/src/a243b0141e6f/deployment/vhost/__init__.py

--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach

Gustaf Nilsson

unread,
Mar 19, 2012, 6:55:45 PM3/19/12
to cherryp...@googlegroups.com
interesting! only problem is that i would like to keep my projects separated from eachother..
But could i have all my app running on separate scripts/ports and then have one proxy CP app that listens on port 80 and then redirects to the different apps? what would that code look like?

thanks
G

On Monday, March 19, 2012 8:07:40 PM UTC, Sylvain Hellegouarch wrote:

Jacob Wan

unread,
Mar 19, 2012, 7:07:58 PM3/19/12
to cherryp...@googlegroups.com
On Mon, Mar 19, 2012 at 3:55 PM, Gustaf Nilsson <gus...@laserpanda.com> wrote:
> interesting! only problem is that i would like to keep my projects separated
> from eachother..
> But could i have all my app running on separate scripts/ports and then have
> one proxy CP app that listens on port 80 and then redirects to the different
> apps? what would that code look like?
>
> thanks
> G

Unless you're just curious, I'm pretty sure you don't even want to
consider that approach. Using a real reverse proxy, you can keep your
applications completely separate. On Windows, IIS+Application Request
Routing is probably the path of least resistance.

Jacob

Gustaf Nilsson

unread,
Mar 21, 2012, 3:50:01 PM3/21/12
to cherryp...@googlegroups.com
I am a little curius now actually.. why is it such a bad idea?



On Monday, March 19, 2012 11:07:58 PM UTC, Jacob Wan wrote:

On Monday, March 19, 2012 11:07:58 PM UTC, Jacob Wan wrote:
On Monday, March 19, 2012 11:07:58 PM UTC, Jacob Wan wrote:

Jacob Wan

unread,
Mar 21, 2012, 4:11:33 PM3/21/12
to cherryp...@googlegroups.com
On Wed, Mar 21, 2012 at 12:50 PM, Gustaf Nilsson <gus...@laserpanda.com> wrote:
> I am a little curius now actually.. why is it such a bad idea?
>
Hi Gustaf,

Unless I'm mistaken, your real goal is to produce webapps, not web
proxies. Maybe some of the web apps are written using Python and
CherryPy, maybe some aren't (e.g. ASP.NET, Spring, etc.) Using the
right tool for the job, or at least a good tool for the job, will help
meet this goal. There are a number of good reverse proxy options
available to forward requests on port 80 to other ports of your
choosing. So unless you're really interested in reinventing that
particular wheel, then my advice would be to select one of these,
become friends with it, and let it do that work for you. Then you can
focus on developing the webapps.

FWIW, I do all my reverse proxying using nginx. It's simple to setup
and configure. But I'm running on Linux, not Windows.

Robert Brewer

unread,
Mar 21, 2012, 6:19:12 PM3/21/12
to cherryp...@googlegroups.com
Jacob's right: don't bother.

But if anyone did decide to try this, they shouldn't use CherryPy's application layer, because WSGI contains some one-way transformations and limitations that prohibit creation of a generic HTTP proxy. You might be able to use CherryPy's HTTP server without WSGI, but if you wanted to pursue that, you should start with Cheroot [1], which is CherryPy's HTTP server broken out into its own project.


Robert Brewer
fuma...@aminus.org

[1] https://bitbucket.org/cherrypy/cheroot

> --
> You received this message because you are subscribed to the Google
> Groups "cherrypy-users" group.
> To post to this group, send email to cherryp...@googlegroups.com.
> To unsubscribe from this group, send email to cherrypy-

> users+un...@googlegroups.com.

Gustaf Nilsson

unread,
Mar 21, 2012, 8:43:22 PM3/21/12
to cherryp...@googlegroups.com
Ok ok i am now convinced this should not be done in CP.
Problem is i cant get IIS running properly, lighttpd is acting up, portfusion crashes, i hate apache, my dlink router cant do it, im running out of options!

I guess nginx is next, but that will probably cost me another day of headache. :) 

G

> To post to this group, send email to cherrypy-users@googlegroups.com.


> To unsubscribe from this group, send email to cherrypy-

Lakin Wecker

unread,
Mar 22, 2012, 1:17:45 AM3/22/12
to cherryp...@googlegroups.com
I've been toying with writing and maintaining a cherrypy based (or WSGI based) reverse proxy for quite some time.  I think I'd probably always use nginx as the real proxy on a production server myself - but a reverse proxy in WSGI would come in useful during development, for instance.

There is already one in existence: http://darcs.idyll.org/~t/projects/scotch/scotch/proxy.py

I'm not sure how well it actually works.  A combination of cherrypy's virtual host dispatcher and this WSGI app might do what you're looking for.  I'm also not familiar with the one way transformations that Robert was referring to, but if your apps don't make use of those you might get away with it.

With the ease of running an Ubuntu machine in a VM like Virtual box along with using nginx as the reverse proxy, I have a hard time using or recommending any other solution.  If it were me, however, I'd host the Ubuntu server on a linode - not on my on home server.

Lakin

To view this discussion on the web visit https://groups.google.com/d/msg/cherrypy-users/-/6-Upb0t-Qj0J.

To post to this group, send email to cherryp...@googlegroups.com.
To unsubscribe from this group, send email to cherrypy-user...@googlegroups.com.

Sylvain Hellegouarch

unread,
Mar 22, 2012, 3:31:15 AM3/22/12
to cherryp...@googlegroups.com
On Thu, Mar 22, 2012 at 1:43 AM, Gustaf Nilsson <gus...@laserpanda.com> wrote:
Ok ok i am now convinced this should not be done in CP.
Problem is i cant get IIS running properly, lighttpd is acting up, portfusion crashes, i hate apache, my dlink router cant do it, im running out of options!

I guess nginx is next, but that will probably cost me another day of headache. :) 

G


You didn't seem to initially request for turning CP into a reverse proxy but you wanted to server different subdomains in one single CP instance which CP virtual hosting nicely does. If you want a reverse proxy, indeed, as the others said, CP shouldn't be used for that. Nginx is a common tool for such task. As pure proxies go, haproxy is a very useful tool. Lately I've also looked at sec-wall: http://sec-wall.gefira.pl

Reply all
Reply to author
Forward
0 new messages