Re: Serving two different ports within a single script
Sylvain Hellegouarch <[email protected]>
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <CALkdAkgJ4gL-m+_627zCq+eMRA-sTCOJ8eDDa1HEwUsb_wV3bg@mail.gmail.com> |
Hi there,
I think you need to create another HTTP server that will also listen on
port 443.
http://docs.cherrypy.org/en/latest/advanced.html#multiple-http-servers-support
http://docs.cherrypy.org/en/latest/deploy.html#ssl-support
- Sylvain
2016-06-03 17:29 GMT+02:00 <eloi.le-bastart-de-villeneuve-wfpxC6D80PtWj0EZb7rXcA@public.gmane.org>:
> Hi,
>
> I've been using Cherrypy for a few days, and despite an intense tracking
> through the scarce and elliptic doc, I didn't manage to serve two different
> apps on two different ports of my server.
>
> My strategy is to provide a simple hello world script to the port 443 and
> a redirect when you call port 80. Here is the code :
> import cherrypy
>
> class HelloWorld:
> @cherrypy.expose
> def index(self):
> return "Hello World!"
>
> class Redirect:
> @cherrypy.expose
> def index(self):
> raise cherrypy.HTTPRedirect("https://whatever.url.com")
>
>
> root = HelloWorld()
> RootApp = cherrypy.Application(root)
> hello_world = cherrypy.Application(root)
>
> redirect = cherrypy.Application(Redirect())
>
> vh = cherrypy._cpwsgi.VirtualHost(root,
> domains={
> '0.0.0.0:443' : hello_world,
> '0.0.0.0:80' : redirect
> }
> )
>
> cherrypy.tree.mount(root, "/", conf)
> cherrypy.tree.graft(vh)
>
>
> cherrypy.config.update({
> 'log.access_file': "access1.log",
> 'log.screen' : True,
> 'tools.sessions.on': True,
> 'server.socket_host' : '0.0.0.0',
> 'server.socket_port' : 80,
> 'server.ssl_module' : 'builtin'
> })
>
> cherrypy.engine.start()
> cherrypy.engine.block()
>
> Right now this doesn't even work anymore ; I'm getting a
> 'HelloWorld' object is not callable
> answer.
>
> But if I happen to remove this part :
> root = HelloWorld()
> RootApp = cherrypy.Application(root)
> hello_world = cherrypy.Application(root)
>
> redirect = cherrypy.Application(Redirect())
>
> vh = cherrypy._cpwsgi.VirtualHost(root,
> domains={
> '0.0.0.0:443' : hello_world,
> '0.0.0.0:80' : redirect
> }
> )
>
> cherrypy.tree.mount(root, "/", conf)
> cherrypy.tree.graft(vh)
>
> which causes the previous issue, visiting http://localhost/ just (almost)
> randomly redirects to https://whatever.url.com/
>
> How do i get
>
> - http://localhost:443 to execute HelloWorld
> - http://localhost:80 to redirect
>
> in the same script?
>
> Thank you in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "cherrypy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> Visit this group at https://groups.google.com/group/cherrypy-users.
> For more options, visit https://groups.google.com/d/optout.
>
--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.