I''m using the instructions from http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/to configure mongrel_cluster with apache mod_proxy_balancer. Everything works fine, except when I try to link to a pdf file to be opened in a new window, it displays the contents of the pdf as text instead of opening it as a pdf document through Acrobat. If I try adding a link to a pdf file in a regular html file (as in under ~/public_html) which is served directly by apache (and not by mongrel), it works properly.. I''m not sure exactly how to configure mongrel/apache to play nicely with pdf files.. Is this happening because I haven''t told apache that pdf files are static content and should be handled by it rather than mongrel? If anyone has any suggestions on how to get this to work, please let me know. Thanks, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060707/a9621f26/attachment.html
okay, I managed to solve the problem by creating a mime.types file with ".pdf: application/pdf" and referencing it using ":mime_map config/mime.types". The problem is, this means that the pdf file is being served by mongrel, whereas it should be served as a static file via apache. In my rewrite log, I see the following: (3) applying pattern ''^/$'' to uri ''/pdfs/instructions.pdf'' (3) applying pattern ''^([^.]+)$'' to uri ''/pdfs/instructions.pdf'' (3) applying pattern ''^/(.*)$'' to uri ''/pdfs/instructions.pdf'' (4) RewriteCond: (3) input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public/pdfs/instructions.pdf'' (3) pattern=''!-f'' => not-matched (1) pass through /pdfs/instructions.pdf and I''m using the following rewrite rules: # Rewrite index to check for static RewriteRule ^/$ /index.html [QSA] # Rewrite to check for Rails cached page RewriteRule ^([^.]+)$ $1.html [QSA] # Redirect all non-static requests to cluster RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mls%{REQUEST_URI} [P,QSA,L] so doesn''t "pass through" mean that the file is being passed through to apache to be served statically? I have sendfile installed, so does that mean that it''s using sendfile to give apache a reference to the file, and so that may be why it''s having trouble with mime type (since maybe apache doesn''t use it''s own mime type when being passed a reference via sendfile)? I just want to make sure that I''m doing this the correct way and that my static files are being served statically. Am I doing the right thing by adding the mime type to the mongrel mime_map file? Thanks, Mike On 7/7/06, Mike Garey <random49k at gmail.com> wrote:> > I''m using the instructions from http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/ > to configure mongrel_cluster with apache mod_proxy_balancer. Everything > works fine, except when I try to link to a pdf file to be opened in a new > window, it displays the contents of the pdf as text instead of opening it as > a pdf document through Acrobat. If I try adding a link to a pdf file in a > regular html file (as in under ~/public_html) which is served directly by > apache (and not by mongrel), it works properly.. I''m not sure exactly how to > configure mongrel/apache to play nicely with pdf files.. Is this happening > because I haven''t told apache that pdf files are static content and should > be handled by it rather than mongrel? If anyone has any suggestions on how > to get this to work, please let me know. Thanks, > > Mike >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060707/a57dad56/attachment.html
On Fri, Jul 07, 2006 at 05:42:56PM -0400, Mike Garey wrote:> okay, I managed to solve the problem by creating a mime.types file with > ".pdf: application/pdf" and referencing it using ":mime_map > config/mime.types". The problem is, this means that the pdf file is being > served by mongrel, whereas it should be served as a static file via apache. > In my rewrite log, I see the following: > > (3) applying pattern ''^/$'' to uri ''/pdfs/instructions.pdf'' > (3) applying pattern ''^([^.]+)$'' to uri ''/pdfs/instructions.pdf'' > (3) applying pattern ''^/(.*)$'' to uri ''/pdfs/instructions.pdf'' > (4) RewriteCond: > (3) > input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public/pdfs/instructions.pdf'' > (3) pattern=''!-f'' => not-matched > (1) pass through /pdfs/instructions.pdfimho this means that Apache is serving the file itself. Just to be sure you could stop mongrel and hit the same URL again. If you get the file, it is clearly served by Apache. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
if I shut down mongrel, I get the following: Service Temporarily Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. so it looks like it _is_ being served through mongrel.. I guess this means my rewrite rules aren''t actually serving the static files through apache.. Any ideas? Mike On 7/7/06, Jens Kraemer <kraemer at webit.de> wrote:> On Fri, Jul 07, 2006 at 05:42:56PM -0400, Mike Garey wrote: > > okay, I managed to solve the problem by creating a mime.types file with > > ".pdf: application/pdf" and referencing it using ":mime_map > > config/mime.types". The problem is, this means that the pdf file is being > > served by mongrel, whereas it should be served as a static file via apache. > > In my rewrite log, I see the following: > > > > (3) applying pattern ''^/$'' to uri ''/pdfs/instructions.pdf'' > > (3) applying pattern ''^([^.]+)$'' to uri ''/pdfs/instructions.pdf'' > > (3) applying pattern ''^/(.*)$'' to uri ''/pdfs/instructions.pdf'' > > (4) RewriteCond: > > (3) > > input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public/pdfs/instructions.pdf'' > > (3) pattern=''!-f'' => not-matched > > (1) pass through /pdfs/instructions.pdf > > imho this means that Apache is serving the file itself. > > Just to be sure you could stop mongrel and hit the same URL > again. If you get the file, it is clearly served by Apache. > > Jens > > > -- > webit! Gesellschaft f?r neue Medien mbH www.webit.de > Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de > Schnorrstra?e 76 Tel +49 351 46766 0 > D-01069 Dresden Fax +49 351 46766 66 > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
On Fri, 2006-07-07 at 17:42 -0400, Mike Garey wrote:> so doesn''t "pass through" mean that the file is being passed through > to apache to be served statically? I have sendfile installed, so does > that mean that it''s using sendfile to give apache a reference to the > file, and so that may be why it''s having trouble with mime type (since > maybe apache doesn''t use it''s own mime type when being passed a > reference via sendfile)?I believe you''ve got it backwards, but the mod_rewrite stuff is so dense I could never remember what directive did was exactly. The only thing I do is I setup a stock set of instructions (Bradley Taylor had some) and then turn on insane mod_rewrite debugging. No matter what the docs say, if the debug output says that it''s not serving the file statically then you don''t have your config right. I''ll dig into some of my other configs and see if you''ve got a simple "one-char-fix" problem. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
On Friday 07 July 2006 15:30, Mike Garey wrote:> if I shut down mongrel, I get the following: > > Service Temporarily Unavailable > > The server is temporarily unable to service your request due to > maintenance downtime or capacity problems. Please try again later. > > so it looks like it _is_ being served through mongrel.. I guess this > means my rewrite rules aren''t actually serving the static files > through apache.. Any ideas? > > Mike >What are your proxy rules? Unless you have excluded these directories, and after rewriting they still fit one of your proxy rules, (from what you have shown so far, it looks like it will), it will be proxied with the rewritten url. -- John E. Kienitz Jr. GPG-FP: 4992 D6E9 774B BA0A CE13 3E2B D6B3 827E 5736 D958 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20060707/a4c4505b/attachment.bin
On Fri, Jul 07, 2006 at 06:30:42PM -0400, Mike Garey wrote:> if I shut down mongrel, I get the following: > > Service Temporarily Unavailable > > The server is temporarily unable to service your request due to > maintenance downtime or capacity problems. Please try again later. > > so it looks like it _is_ being served through mongrel.. I guess this > means my rewrite rules aren''t actually serving the static files > through apache.. Any ideas?how is your mod_proxy configured ? Do you use ProxyPass or do you Proxy by using [P] with a rewrite rule ? Posting your virtual host''s apache configuration might help. Jens> > Mike > > On 7/7/06, Jens Kraemer <kraemer at webit.de> wrote: > > On Fri, Jul 07, 2006 at 05:42:56PM -0400, Mike Garey wrote: > > > okay, I managed to solve the problem by creating a mime.types file with > > > ".pdf: application/pdf" and referencing it using ":mime_map > > > config/mime.types". The problem is, this means that the pdf file is being > > > served by mongrel, whereas it should be served as a static file via apache. > > > In my rewrite log, I see the following: > > > > > > (3) applying pattern ''^/$'' to uri ''/pdfs/instructions.pdf'' > > > (3) applying pattern ''^([^.]+)$'' to uri ''/pdfs/instructions.pdf'' > > > (3) applying pattern ''^/(.*)$'' to uri ''/pdfs/instructions.pdf'' > > > (4) RewriteCond: > > > (3) > > > input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public/pdfs/instructions.pdf'' > > > (3) pattern=''!-f'' => not-matched > > > (1) pass through /pdfs/instructions.pdf > > > > imho this means that Apache is serving the file itself. > > > > Just to be sure you could stop mongrel and hit the same URL > > again. If you get the file, it is clearly served by Apache. > > > > Jens > > > > > > -- > > webit! Gesellschaft f?r neue Medien mbH www.webit.de > > Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de > > Schnorrstra?e 76 Tel +49 351 46766 0 > > D-01069 Dresden Fax +49 351 46766 66 > > _______________________________________________ > > Mongrel-users mailing list > > Mongrel-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mongrel-users > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users-- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote:> On Fri, Jul 07, 2006 at 06:30:42PM -0400, Mike Garey wrote: > > if I shut down mongrel, I get the following: > > > > Service Temporarily Unavailable > > > > The server is temporarily unable to service your request due to > > maintenance downtime or capacity problems. Please try again later. > > > > so it looks like it _is_ being served through mongrel.. I guess this > > means my rewrite rules aren''t actually serving the static files > > through apache.. Any ideas? > > how is your mod_proxy configured ? Do you use ProxyPass or do you Proxy > by using [P] with a rewrite rule ? > > Posting your virtual host''s apache configuration might help.I''m using pretty much the exact same configuration as outlined in the site <http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/> <VirtualHost *:80> ServerName myapp.mydomain.com DocumentRoot /usr/local/www/data/vhosts/www.mydomain.com/current/public <Directory "/usr/local/www/data/vhosts/www.mydomain.com/current/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> ProxyPass / balancer://myapp/ ProxyPassReverse / balancer://myapp/ RewriteEngine On # Check for maintenance file and redirect all requests RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L] # Rewrite index to check for static RewriteRule ^/$ /index.html [QSA] # Rewrite to check for Rails cached page RewriteRule ^([^.]+)$ $1.html [QSA] # Redirect all non-static requests to cluster RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://myapp%{REQUEST_URI} [P,QSA,L] ErrorLog /var/log/apache22/myapp_errors_log CustomLog /var/log/apache22/myapp_log combined </VirtualHost> now, I don''t know much about url rewriting, but it looks like it only sends a request through the balancer if a file with the requeted name doesn''t exist.. So I can''t understand why static files will no longer work if I shutdown mongrel.. In theory, I should be able to stop mongrel and have _all_ my static files served directly through apache Does anyone have any other rewrite rules I should be looking at? John Kienitz posted the following proxypass/rewrite rules in a message entitled "Apache 2.0 proxy" sent to the list a few days ago: RewriteRule ^/myrailsapp/images(.*) /myrailsapp/public/images$1 RewriteRule ^/myrailsapp/javascripts(.*) /myrailsapp/public/javascripts$1 RewriteRule ^/myrailsapp/stylesheets(.*) /myrailsapp/public/stylesheets$1 ProxyPass /myrailsapp/images ! ProxyPass /myrailsapp/javascrripts ! ProxyPass /myrailsapp/stylesheets ! which looks like it may explicitly tell apache not to send any requests for files in images, javascripts or stylesheets through the proxy balancer (although shouldn''t I get the same results by telling apache to only pass requests through the balancer if a file with the requested name doesn''t exist?). It seems I''m a bit confused about configuring the proxy balancer and using rewrite rules (I was hoping that this would *just work* and I could avoid having to spend too much time learning about either of these options, you know, the whole "convention over configuration" thing ;) I''m scheduled to deploy my app pretty soon, so hopefully I can get this all sorted out before tthen. Thanks for your help, Mike
On Mon, Jul 10, 2006 at 09:14:01AM -0400, Mike Garey wrote:> On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote: > > On Fri, Jul 07, 2006 at 06:30:42PM -0400, Mike Garey wrote:[..]> > > <VirtualHost *:80> > ServerName myapp.mydomain.com > DocumentRoot /usr/local/www/data/vhosts/www.mydomain.com/current/public > > <Directory "/usr/local/www/data/vhosts/www.mydomain.com/current/public"> > Options FollowSymLinks > AllowOverride None > Order allow,deny > Allow from all > </Directory> > > ProxyPass / balancer://myapp/ > ProxyPassReverse / balancer://myapp/^^^ These two lines will make Apache pass *all* requests below / to the balancer. try commenting them out, the [P] rewrite rule should be enough. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote:> On Mon, Jul 10, 2006 at 09:14:01AM -0400, Mike Garey wrote: > > On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote: > > > On Fri, Jul 07, 2006 at 06:30:42PM -0400, Mike Garey wrote: > [..] > > > > > > <VirtualHost *:80> > > ServerName myapp.mydomain.com > > DocumentRoot /usr/local/www/data/vhosts/www.mydomain.com/current/public > > > > <Directory "/usr/local/www/data/vhosts/www.mydomain.com/current/public"> > > Options FollowSymLinks > > AllowOverride None > > Order allow,deny > > Allow from all > > </Directory> > > > > ProxyPass / balancer://myapp/ > > ProxyPassReverse / balancer://myapp/ > > ^^^ > > These two lines will make Apache pass *all* requests below / to the > balancer. try commenting them out, the [P] rewrite rule should be > enough.I commented out those two lines and sure enough, apache will serve static content even when mongrel is stopped.. What I don''t understand though is that regardless of whether the two lines are enabled/disabled, my rewrite log shows the same thing: (2) init rewrite engine with requested uri /images/common/learn_more.gif (3) applying pattern ''^.*$'' to uri ''/images/common/learn_more.gif'' (4) RewriteCond: input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public/system/maintenance.html'' pattern=''-f'' => not-matched (3) applying pattern ''^/$'' to uri ''/images/common/learn_more.gif'' (3) applying pattern ''^([^.]+)$'' to uri ''/images/common/learn_more.gif'' (3) applying pattern ''^/(.*)$'' to uri ''/images/common/learn_more.gif'' (4) RewriteCond: input=''/usr/local/www/data/vhosts/www.mydomain.com/current/public//images/common/learn_more.gif'' pattern=''!-f'' => not-matched (1) pass through /images/common/learn_more.gif so it looks like it''s passing the files directly through apache in both cases, yet it will only work if mongrel is started when the ProxyPass lines are enabled.. (otherwise I get the service temporarily unavailable message). So to break it down, I have the following 3 scenarios: 1) mongrel_cluster is runnning, ''ProxyPass / balancer://myapp/'' and ''ProxyPassReverse / balancer://myapp/'' are enabled -> both static content and dynamic content is served 2) mongrel_cluster is stopped ''ProxyPass / balancer://myapp/'' and ''ProxyPassReverse / balancer://myapp/'' are enabled -> neither static nor dynamic content is served 3) mongrel_cluster is stopped ''ProxyPass / balancer://myapp/'' and ''ProxyPassReverse / balancer://myapp/'' are disabled-> static content is served, dynamic content isn''t So this all makes sense, the only thing that''s confusing is: A) the rewrite log contains the same thing in all 3 scenarios (you''d think in scenario 1 that it would show that the requests for static content are actually being sent through the balancer, rather than showing "pass through", which seems to indicate that it''s being served directly by apache) B) The fact that none of the comments on the original tutorial site <http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/> mention anything about these ''ProxyPass /'' lines preventing any static content being served by apache. This is of course not to say that I should take the instructions on that website as 100% accurate, but it just makes me want to double check that I''m indeed doing the right thing. Anyway, thanks for the help guys, so far everything seems to be working the way I want. Mike
On Mon, Jul 10, 2006 at 01:04:59PM -0400, Mike Garey wrote:> On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote: > > On Mon, Jul 10, 2006 at 09:14:01AM -0400, Mike Garey wrote: > > > On 7/10/06, Jens Kraemer <kraemer at webit.de> wrote: > > > > On Fri, Jul 07, 2006 at 06:30:42PM -0400, Mike Garey wrote:[..]> > > > > > ProxyPass / balancer://myapp/ > > > ProxyPassReverse / balancer://myapp/ > > > > ^^^ > > > > These two lines will make Apache pass *all* requests below / to the > > balancer. try commenting them out, the [P] rewrite rule should be > > enough. > > I commented out those two lines and sure enough, apache will serve > static content even when mongrel is stopped.. What I don''t understand > though is that regardless of whether the two lines are > enabled/disabled, my rewrite log shows the same thing: >[..]> so it looks like it''s passing the files directly through apache in > both cases, yet it will only work if mongrel is started when the > ProxyPass lines are enabled.. (otherwise I get the service temporarily > unavailable message). > > So to break it down, I have the following 3 scenarios: > > 1) mongrel_cluster is runnning, ''ProxyPass / balancer://myapp/'' and > ''ProxyPassReverse / balancer://myapp/'' are enabled -> both static > content and dynamic content is served > > 2) mongrel_cluster is stopped ''ProxyPass / balancer://myapp/'' and > ''ProxyPassReverse / balancer://myapp/'' are enabled -> neither static > nor dynamic content is served > > 3) mongrel_cluster is stopped ''ProxyPass / balancer://myapp/'' and > ''ProxyPassReverse / balancer://myapp/'' are disabled-> static content > is served, dynamic content isn''t > > So this all makes sense, the only thing that''s confusing is: > > A) the rewrite log contains the same thing in all 3 scenarios (you''d > think in scenario 1 that it would show that the requests for static > content are actually being sent through the balancer, rather than > showing "pass through", which seems to indicate that it''s being served > directly by apache)actually, the rewrite rules are always executed, that''s why the rewrite log is the same in any case. ProxyPass, if present, will then step in after the ''pass through'', forwarding your request to mongrel, regardless of any rewriting done before, since the / pattern always matches.> B) The fact that none of the comments on the original tutorial site > <http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/> > mention anything about these ''ProxyPass /'' lines preventing any static > content being served by apache. This is of course not to say that I > should take the instructions on that website as 100% accurate, but it > just makes me want to double check that I''m indeed doing the right > thing.that may be because it''s an issue one doesn''t notice in the first place, as everything appears to be working fine.> Anyway, thanks for the help guys, so far everything seems to be > working the way I want.glad to help :) Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66