[Twisted-Python] HTTP 302 instead of just delivering the content.
Hi, I'm using twisted-web on port 8083 and apache as a reverse proxy on port 80. I can connect to my domain on port 80 and the HTTP request gets forwarded to twisted correctly. Twisted also replies and I get the website. But as soon as I click a link, the 8083 port appears in the URL. And according to tcpdump, it also got transfered via 8083. I figured Twisted replied with the following (my real domain replaced by some 'x'): HTTP/1.1 302 Found Date: Mon, 11 Sep 2006 12:22:57 GMT Server: TwistedWeb/2.4.0+r17646 Content-type: text/html; charset=UTF-8 Location: http://www.xxxxxxxx.ch:8083/firma/ Transfer-Encoding: chunked Why does it do that? The request sent was: GET /firma HTTP/1.1 Host: www.xxxxxxxxx.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 (Debian-1.5.dfsg+1.5.0.6-4) .... The apache2 reverse proxy configuration part is: RewriteRule ^(.*)$ http://localhost:8083$1 [P] ProxyRequests Off ProxyPreserveHost On ProxyVia Off <Proxy *> Order deny,allow Allow from all </Proxy> How can I tell twisted to not only accept requests on port 8083, but also serve those with Host: www.xxxxxxxxx.ch? Regards Markus
Markus Schiltknecht wrote:
Hi,
I'm using twisted-web on port 8083 and apache as a reverse proxy on port 80. I can connect to my domain on port 80 and the HTTP request gets forwarded to twisted correctly. Twisted also replies and I get the website.
But as soon as I click a link, the 8083 port appears in the URL. And according to tcpdump, it also got transfered via 8083. I figured Twisted replied with the following (my real domain replaced by some 'x'):
HTTP/1.1 302 Found Date: Mon, 11 Sep 2006 12:22:57 GMT Server: TwistedWeb/2.4.0+r17646 Content-type: text/html; charset=UTF-8 Location: http://www.xxxxxxxx.ch:8083/firma/ Transfer-Encoding: chunked
Why does it do that? The request sent was:
GET /firma HTTP/1.1 Host: www.xxxxxxxxx.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6 (Debian-1.5.dfsg+1.5.0.6-4) ....
The apache2 reverse proxy configuration part is:
RewriteRule ^(.*)$ http://localhost:8083$1 [P]
ProxyRequests Off ProxyPreserveHost On
ProxyVia Off
<Proxy *> Order deny,allow Allow from all </Proxy>
How can I tell twisted to not only accept requests on port 8083, but also serve those with Host: www.xxxxxxxxx.ch?
You need a vhostmonster http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.h...
Hi, Phil Mayers wrote:
You need a vhostmonster
Thank you, I didn't think about a vhostmonster, because I don't want to serve multiple vhosts. I only want to serve _one_ website. It gets accessed from different URLs, though. As I'm using nevow, I think I have to use the nevow vhost thingie: from nevow import appserver from nevow import vhost root = vhost.NameVirtualHost() webroot = Website('sites') webroot.putChild('xxxxxx.ch', root) webroot.putChild('www.xxxxxx.ch', root) site = appserver.NevowSite(webroot) webserver = internet.TCPServer(8083, site) application = service.Application('ulmann website') webserver.setServiceParent(application) But, that works as before: it still redirects to port 8083 instead of just ignoring the HTTP Host: Header field. Can't I just tell twisted web to ignore that? Without VHostMonsters and stuff like that? IMHO twisted should not mind and just serve what it's told to serve on port 8083. And let apache do the reverse proxying. Regards Markus
On Tue, Sep 12, 2006 at 10:41:16AM +0200, Markus Schiltknecht wrote:
Hi,
Phil Mayers wrote:
You need a vhostmonster
Thank you, I didn't think about a vhostmonster, because I don't want to serve multiple vhosts. I only want to serve _one_ website. It gets accessed from different URLs, though.
As I'm using nevow, I think I have to use the nevow vhost thingie:
from nevow import appserver from nevow import vhost
Nevow has a VHostMonster.
root = vhost.NameVirtualHost()
webroot = Website('sites') webroot.putChild('xxxxxx.ch', root) webroot.putChild('www.xxxxxx.ch', root)
What do you expect this to do?
site = appserver.NevowSite(webroot) webserver = internet.TCPServer(8083, site)
application = service.Application('ulmann website') webserver.setServiceParent(application)
See: http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.h... The usage is exactly the same for Nevow's VHostMonster.
But, that works as before: it still redirects to port 8083 instead of just ignoring the HTTP Host: Header field.
Can't I just tell twisted web to ignore that? Without VHostMonsters and stuff like that? IMHO twisted should not mind and just serve what it's told to serve on port 8083. And let apache do the reverse proxying.
It's an issue of URL generation from the request object. There is no good way to make the right thing just magically happen. Because as usual your right thing will be different from someone elses. VHostMonster is an atrocity though, someone should seriously consider backporting the *VHostURIRewrite resources in twisted.web2.vhost. I'll go get the bear. -David -- "Usually the protocol is this: I appoint someone for a task, which they are not qualified to do. Then, they have to fight a bear if they don't want to do it." -- Glyph Lefkowitz
David Reid wrote:
Nevow has a VHostMonster.
Yes. So?
webroot = Website('sites') webroot.putChild('xxxxxx.ch', root) webroot.putChild('www.xxxxxx.ch', root)
What do you expect this to do?
the same as root.addHost() in the twisted VHostMonster.
See: http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.h... The usage is exactly the same for Nevow's VHostMonster.
Hm.. I've tried that but didn't manage to get twisted to correctly answer HTTP requests anymore. Thus I've been googling and figured out, that Nevow didn't work well with the VHostMonster and thus provides it's own. Anyway, the code in the docu is: root = vhost.NameVirtualHost() root.addHost(vhostName, reverseProxy) site = server.Site(root) application = service.Application('web-proxy') sc = service.IServiceCollection(application) i = internet.TCPServer(80, site) i.setServiceParent(sc) Now, I don't have a reverseProxy, but a NevowSite(). Unfortunately that's a 'Site' and not a 'Resource' (whatever the exact difference is).
It's an issue of URL generation from the request object.
Where does twisted need to generate a URL? I'm even mostly using relative links, AFAICR... Regards Markus
This discussion would be more appropriate on the twisted-web mailing list. Jean-Paul
participants (4)
-
David Reid -
Jean-Paul Calderone -
Markus Schiltknecht -
Phil Mayers