Will,
Yes it’s the case that a front-end web server (nginx) is sitting in
front of the mongrels but no it’s not the case that it is misconfigured.
As I hoped my example was illustrating, the web server knows about
different virtual hosts but mongrel doesn’t.
Let me try and give another example with even more detail:
Assume:
-
Mongrel (without patch), which serves any static files it finds in
it’s doc root (RAILS_ROOT/public)
-
Web server (WS) virtual host mapping:
-
example.com => /var/www/apps/example.com/public (web
server’s doc root for virtual host 1)
-
es.example.com => /var/www/apps/example.com/public/es (web
server’s doc root for virtual host 2)
directory structure (DS) when cache is cleared:
RAILS_ROOT/public
RAILS_ROOT/public/es
Steps on 1st request: http://example.com
- WS: can’t find index.html in /var/www/apps/example.com/public
- WS forwards request to mongrel process (M)
- M can’t find index.html in /var/www/apps/example.com/public
- Mongrel creates a rails process to handle request for /
- Rails, sees example.com host and / path and renders index.html in /
var/www/apps/example.com/public
- Mongrel serves /var/www/apps/example.com/public/index.html back
There’s no problem at this point. But bear with me…
DS is now:
RAILS_ROOT/public
RAILS_ROOT/public/index.html
RAILS_ROOT/public/es
Steps on 2nd request: http://example.com
- WS: finds index.html in /var/www/apps/example.com/public
- WS serves request
Again, no problem…just served up previously cached file from same
domain.
DS is still:
RAILS_ROOT/public
RAILS_ROOT/public/index.html
RAILS_ROOT/public/es
Steps on 3rd request: http://es.example.com
- WS: can’t find index.html in /var/www/apps/example.com/public/es <=
Note the doc root is different
- WS forwards request to mongrel process (M)
- M finds index.html in /var/www/apps/example.com/public
- Mongrel serves /var/www/apps/example.com/public/index.html which is
the page associated with the http://example.com domain.
- This is NOT the required behaviour as it’s serving the cached file
for http://example.com rather than http://es.example.com as was
requested.
DS is still:
RAILS_ROOT/public
RAILS_ROOT/public/index.html
RAILS_ROOT/public/es
Alternative 3rd request (http://es.example.com) with * patched mongrel
- (mongrel set NOT to serve any static files):
- WS: can’t find index.html in /var/www/apps/example.com/public/es
- WS forwards request to mongrel process (M)
- M ignores index.html in /var/www/apps/example.com/public as it
directly forwards request to rails
- Mongrel creates a rails process to handle request
- Rails, sees es.example.com host and / path and renders index.html
in /var/www/apps/example.com/public/es
- Mongrel serves /var/www/apps/example.com/public/es/index.html back
DS is now:
RAILS_ROOT/public
RAILS_ROOT/public/index.html
RAILS_ROOT/public/es
RAILS_ROOT/public/es/index.html
Note: Now the right page has been served for the right domain. After
the file has been cached for http://es.example.com, the WS will
happily serve that up.
Phew, I hope this finally illustrates the problem with more clarity.
Regards,
Saimon
On Jan 25, 2008, at 3:32 PM, Will G. wrote:
it and calls rails to render it.
example.com/
to rails, on the second request rails (using the host info) would
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-users
–
Saimon M.
Freelance Web D.
(Available for hire - For details visit http://saimonmoore.net)
Skype: saimonmoore
Yahoo IM: saimonmoore
Google IM: saimonmoore