[Twisted-web] reverse proxy with nevow
Mike Mueller
pyp at gmx.net
Sun Nov 7 05:36:19 MST 2004
After fiddling for quite a while I am running out of ideas how get the
following to work.
I would like to run a nevow site on port 8080 on the same machine I run a
twisted web
server that serves static pages. Instead of showing the 8080 in the address
I would like
to run the nevow site as VHostMonsterResource.
My twisted web server looks like this:
#twistedStaticServer.py
from twisted.web import vhost, static, server, proxy
from twisted.application import internet, service
import os
vhostDir = '..\hosts'
root = vhost.NameVirtualHost()
dir = 'domain1.com'
root.addHost(dir, static.File(os.path.join(vhostDir, dir)))
vhostName = 'domain2.com'
reverseProxy = proxy.ReverseProxyResource('localhost', 8080,
'/vhost/http/'+vhostName)
root.addHost(vhostName, reverseProxy)
application = service.Application('web')
sc = service.IServiceCollection(application)
site = server.Site(root)
i = internet.TCPServer(80, site)
i.setServiceParent(sc)
The nevow site looks like this:
#nevowProxy.py
import random
from nevow import appserver, vhost
from twisted.application import internet, service
from nevow import rend, tags
from nevow import loaders
vResource = vhost.VHostMonsterResource()
class VHostGreeter(rend.Page):
docFactory = loaders.stan(
tags.html[
tags.head[ tags.title[ "Runnig as VHostMonsterResource" ]],
tags.body[
tags.h1(style="font-size: large")[ "This works." ]
]
])
default = VHostGreeter()
default.putChild("vhost", vResource)
application = service.Application('web-proxy')
sc = service.IServiceCollection(application)
site = appserver.NevowSite(default)
i = internet.TCPServer(8080, site)
i.setServiceParent(sc)
After modifying /etc/hosts (or C:\WINNT\system32\drivers\etc\hosts):
127.0.0.1 domain1.com
127.0.0.1 domain2.com
domain1.com works as expected. It serves static pages out of the given
directory.
Also domain2.com:8080 works.
But domain2.com just shows an empty page.
I tested this with Opera 7.11 and IE 6.0.
The nevow server gets an GET request. There is no difference in the server
messages
between a direct call (8080) or using it as a reverse proxy:
Opera:
domain2.com:
2004/11/07 13:06 Westeuropõische Normalzeit [HTTPChannel,1,127.0.0.1] 127.0.0.1
- - [07/Nov/2004:12:06:20 +0000] "GET / HTTP/1.0" 200 129 "-" "Mozilla/4.0
(comp
atible; MSIE 6.0; Windows NT 5.0) Opera 7.11 [de]"
domain2.com:8080:
2004/11/07 13:06 Westeuropõische Normalzeit [HTTPChannel,2,127.0.0.1] 127.0.0.1
- - [07/Nov/2004:12:06:32 +0000] "GET / HTTP/1.1" 200 129 "-" "Mozilla/4.0
(comp
atible; MSIE 6.0; Windows NT 5.0) Opera 7.11 [de]"
IE6.0:
domain2.com:
2004/11/07 13:07 Westeuropõische Normalzeit [HTTPChannel,3,127.0.0.1] 127.0.0.1
- - [07/Nov/2004:12:07:25 +0000] "GET / HTTP/1.1" 200 129 "-" "Mozilla/4.0
(comp
atible; MSIE 6.0; Windows NT 5.0)"
domain2.com:8080:
2004/11/07 13:07 Westeuropõische Normalzeit [HTTPChannel,4,127.0.0.1] 127.0.0.1
- - [07/Nov/2004:12:07:46 +0000] "GET / HTTP/1.1" 200 129 "-" "Mozilla/4.0
(comp
atible; MSIE 6.0; Windows NT 5.0)"
The twisted web server shows the following messages:
2004/11/07 13:07 Westeuropõische Normalzeit [HTTPChannel,2,127.0.0.1]
Starting f
actory <twisted.web.proxy.ProxyClientFactory instance at 0x00B716E8>
2004/11/07 13:07 Westeuropõische Normalzeit [ProxyClient,client] Stopping
factor
y <twisted.web.proxy.ProxyClientFactory instance at 0x00B716E8>
How do get the page display when requesting domain2.com?
Thanks.
Mike
More information about the Twisted-web
mailing list