[Twisted-Python] questions on twisted web server
Alex Li
likwoka at yahoo.com
Sun Oct 26 16:14:43 MST 2003
Hi all,
1) I would like to rotate the logs for the web server. How should I do that?
I have read the rotatinglog.py example, but I don't know how to intergrate that
into the web server script below...
2) How to turn off directory listing? Am I doing the right way below?
3) I would like to use https for certain directories, but not the whole site.
How do I do that (probably with 2 server.Site instances... I need more clues)?
For example, if a user access the site through
http://localhost/secure, then he should be redirected to
https://localhost/secure
#--------------------------------------------------------------------------
from twisted.application import internet, service
from twisted.web import static, server, util, error
from OpenSSL import SSL
class ServerContextFactory:
'''Loads a certificate from the file 'server.pem'.'''
def getContext(self):
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_certificate_file('/home/www/snakeoil-rsa.crt')
ctx.use_privatekey_file('/home/www/snakeoil-rsa.key')
return ctx
root = static.File('/home/www/production')
root.ignoreExt('.html')
# turn off directory listing
root.putChild('', error.ForbiddenResource())
site = server.Site(root, logPath='/home/www/access.log')
application = service.Application('web', uid=33, gid=33) #www-data
serviceCollection = service.IServiceCollection(application)
internet.TCPServer(82, site).setServiceParent(serviceCollection)
internet.SSLServer(443, site, ServerContextFactory()
).setServiceParent(serviceCollection)
Thanks in advance,
Alex
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
More information about the Twisted-Python
mailing list