From: Brian C. <B.C...@po...> - 2008-11-27 09:40:28
|
On Wed, Nov 26, 2008 at 02:40:02PM -0500, Bob Calco wrote: > OK, proxying almost works. I am missing only one piece of the puzzle, > which is how to preserve the host name. > > <server www.example.com> > port = 80 > listen = 1.2.3.4 # actual IP not shown > rhost = localhost:3000 > revproxy = / localhost:3000 > </server> > > All is well until I use a URI off the root for example > www.example.com/admin > > It automatically "redirects" me to localhost:3000/admin (or whatever my > Rails routes.rb file tells mongrel to route it to). This works on the > machine in question but not on a remote machine. Do you mean you get back a HTTP redirect to localhost:3000/admin? Or that the page contains links to http://localhost:3000/? Neither should happen. Try a manual HTTP session using telnet from the remote host: telnet 1.2.3.4 80 GET /admin HTTP/1.0 Host: www.example.com <blank line> What do you see? > How do I get Yaws to preserve the host name? Note in apache that is the > function of the ProxyPreserveHost directive. I run Rails (2.1.2 and 1.2.3) behind Apache, and I don't use ProxyPreserveHost. As far as I can tell, all the URL links generated by Rails are relative (/foo/bar), and if you want to generate absolute links you have to supply :only_path=>false, :host=>"somestring" (or put these in default_url_options) If you want to run a single Rails app which serves multiple virtual hosts, then you should be able to inspect the X_FORWARDED_HOST request header, which a well-behaved proxy should add. But that's a very unusual situation. Here are the headers that Apache (2.0) adds: /* Add X-Forwarded-For: so that the upstream has a chance to * determine, where the original request came from. */ apr_table_mergen(r->headers_in, "X-Forwarded-For", r->connection->remote_ip); /* Add X-Forwarded-Host: so that upstream knows what the * original request hostname was. */ if ((buf = apr_table_get(r->headers_in, "Host"))) { apr_table_mergen(r->headers_in, "X-Forwarded-Host", buf); } /* Add X-Forwarded-Server: so that upstream knows what the * name of this proxy server is (if there are more than one) * XXX: This duplicates Via: - do we strictly need it? */ apr_table_mergen(r->headers_in, "X-Forwarded-Server", r->server->server_hostname); I don't know if Yaws adds those headers when proxying, but if not, it probably should. Regards, Brian. |