[Twisted-web] Twisted Web with SSL?
Matt Goodall
matt at pollenation.net
Sat Feb 5 02:29:25 MST 2005
On Fri, 2005-02-04 at 14:58 -0500, James Y Knight wrote:
> On Feb 4, 2005, at 12:56 PM, Jeff Bauer wrote:
> > I've looked for information about implmenting a Twisted
> > web server with SSL, but came up short. A quick scan
> > of mail on this list for the past year doesn't have
> > any discussion about SSL, or I may have just overlooked
> > it.
>
> There's probably no discussion, because it just works.
>
> # Standard startup procedure for HTTP port (you need to have setup site
> above, of course)
> application = service.Application("web")
> i = internet.TCPServer(8080, site)
> i.setServiceParent(service.IServiceCollection(application))
>
> # Add two more lines to start a HTTPs port. (you'll need to have made
> your ssl key/crt beforehand)
> i = internet.SSLServer(8081, site,
> ssl.DefaultOpenSSLContextFactory("ssl.key", "ssl.crt"))
> i.setServiceParent(service.IServiceCollection(application))
There's also twisted.application.strports which, in my opinion, makes
this even easier:
# HTTP on port 8080
s = strports.service('tcp:8080', site)
s.setServiceParent(application)
# HTTPS on port 8443
s = strports.service('ssl:8443:privateKey=ssl.key:certKey=ssl.crt',
site)
s.setServiceParent(application)
Cheers, Matt
More information about the Twisted-web
mailing list