Hello list, Some time ago I was looking for apache (as non balanced proxy) + mongrel configurations. Almost everybody seemed to use similar approaches (one of these could be found @ mongrel.rubygorge.org docs) with mod_rewrite. I don''t use proxy_balancer because I don''t need it at the moment (my site has pretty low traffic). This is apache configuration that I''m using at the moment. It''s tested as Zed suggested (mr start -e production -B) and it looks like all static files are served by apache and dynamic ones be mongrel. Here is my apache config: <VirtualHost *> ServerName myapp.tld ServerAlias www.myapp.tld DocumentRoot /var/www/sites/myapp/current/public <Directory "/var/www/sites/myapp/current/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Check for maintenance file. Let apache load it if it exists RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteRule . /system/maintenance.html [L] # Let apache serve static files RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f RewriteRule (.*) $1 [L] # Don''t do forward proxying ProxyRequests Off # Enable reverse proxying <Proxy *> Order deny,allow Allow from all </Proxy> # Pass other requests to mongrel instance ProxyPass / http://127.0.0.1:8200/ ProxyPassReverse / http://127.0.0.1:8200/ </VirtualHost> It would be great if some expert could take a look at my config and point me at my mistakes etc ! I am asking this because it looks like it just works, and it makes me think that it can''t be so easy :) Thanks, Martins
Hi 13 On Sep 26, 2006, at 3:03 PM, 13 wrote:> Hello list, > > Some time ago I was looking for apache (as non balanced proxy) + > mongrel configurations. Almost everybody seemed to use similar > approaches (one of these could be found @ mongrel.rubygorge.org docs) > with mod_rewrite. I don''t use proxy_balancer because I don''t need it > at the moment (my site has pretty low traffic). This is apache > configuration that I''m using at the moment. It''s tested as Zed > suggested (mr start -e production -B) and it looks like all static > files are served by apache and dynamic ones be mongrel. Here is my > apache config: > > <VirtualHost *> > ServerName myapp.tld > ServerAlias www.myapp.tld > > DocumentRoot /var/www/sites/myapp/current/public > > <Directory "/var/www/sites/myapp/current/public"> > Options FollowSymLinks > AllowOverride None > Order allow,deny > Allow from all > </Directory> > > RewriteEngine On > > # Check for maintenance file. Let apache load it if it exists > RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f > RewriteRule . /system/maintenance.html [L] > > # Let apache serve static files > RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f > RewriteRule (.*) $1 [L] > > # Don''t do forward proxying > ProxyRequests Off > > # Enable reverse proxying > <Proxy *> > Order deny,allow > Allow from all > </Proxy> > > # Pass other requests to mongrel instance > ProxyPass / http://127.0.0.1:8200/ > ProxyPassReverse / http://127.0.0.1:8200/ > > </VirtualHost> > > It would be great if some expert could take a look at my config and > point me at my mistakes etc ! I am asking this because it looks like > it just works, and it makes me think that it can''t be so easy :) >Based on the above rules, Apache will only try to find files that match the request URI, as it is given. This will indeed work for images, SWFs, JS, CSS, and any HTML requested directly. However if you are doing something like Rails'' page caching, and want to serve cached HTML, you will need extra rules to rewrite the URI and have Apache check for that (e.g. if the URI is ''/articles/'' then look for ''/articles/index.html'' on the file system, if that doesn''t exist then forward the original URI to Rails). You can determine which server is serving the files by using curl -I (capital I as in India) (Hello Apache) $ curl -I http://somedomain.com/static/file/url/ HTTP/1.1 200 OK Date: Mon, 11 Sep 2006 23:13:05 GMT Server: Apache/2.2.3 (Unix) Last-Modified: Sun, 10 Sep 2006 18:21:52 GMT ETag: "21ac8f5-9d0a-83f57000" Accept-Ranges: bytes Content-Length: 40202 Vary: Accept-Encoding Connection: close Content-Type: text/html (Hello Mongrel) $ curl -I http://somedomain.com/go_to/rails/ HTTP/1.1 200 OK Date: Mon, 11 Sep 2006 23:13:10 GMT Server: Mongrel 0.3.13.4 Status: 200 OK Cache-Control: no-cache Content-Type: text/html; charset=utf-8 Vary: Accept-Encoding Connection: close> Thanks, > Martins > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >==================Matt Pelletier EastMedia t. 212-967-4239 f. 212-967-4257 m. 917-902-2525 w. www.eastmedia.com
Hi, Thanks for your tip Matt. I have intentionally left out rewrite rules for Rails cached pages simply beacause I don''t use them on my page. My goal was to create fast and as simple as it can be config - no cluster, no caching, no defalate ... My full name is Martins Grunskis. -- Martins On 10/2/06, Matt Pelletier <matt at eastmedia.com> wrote:> Hi 13 > > On Sep 26, 2006, at 3:03 PM, 13 wrote: > > > Hello list, > > > > Some time ago I was looking for apache (as non balanced proxy) + > > mongrel configurations. Almost everybody seemed to use similar > > approaches (one of these could be found @ mongrel.rubygorge.org docs) > > with mod_rewrite. I don''t use proxy_balancer because I don''t need it > > at the moment (my site has pretty low traffic). This is apache > > configuration that I''m using at the moment. It''s tested as Zed > > suggested (mr start -e production -B) and it looks like all static > > files are served by apache and dynamic ones be mongrel. Here is my > > apache config: > > > > <VirtualHost *> > > ServerName myapp.tld > > ServerAlias www.myapp.tld > > > > DocumentRoot /var/www/sites/myapp/current/public > > > > <Directory "/var/www/sites/myapp/current/public"> > > Options FollowSymLinks > > AllowOverride None > > Order allow,deny > > Allow from all > > </Directory> > > > > RewriteEngine On > > > > # Check for maintenance file. Let apache load it if it exists > > RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f > > RewriteRule . /system/maintenance.html [L] > > > > # Let apache serve static files > > RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f > > RewriteRule (.*) $1 [L] > > > > # Don''t do forward proxying > > ProxyRequests Off > > > > # Enable reverse proxying > > <Proxy *> > > Order deny,allow > > Allow from all > > </Proxy> > > > > # Pass other requests to mongrel instance > > ProxyPass / http://127.0.0.1:8200/ > > ProxyPassReverse / http://127.0.0.1:8200/ > > > > </VirtualHost> > > > > It would be great if some expert could take a look at my config and > > point me at my mistakes etc ! I am asking this because it looks like > > it just works, and it makes me think that it can''t be so easy :) > > > > Based on the above rules, Apache will only try to find files that > match the request URI, as it is given. This will indeed work for > images, SWFs, JS, CSS, and any HTML requested directly. However if > you are doing something like Rails'' page caching, and want to serve > cached HTML, you will need extra rules to rewrite the URI and have > Apache check for that (e.g. if the URI is ''/articles/'' then look for > ''/articles/index.html'' on the file system, if that doesn''t exist then > forward the original URI to Rails). > > You can determine which server is serving the files by using curl -I > (capital I as in India) > > (Hello Apache) > $ curl -I http://somedomain.com/static/file/url/ > HTTP/1.1 200 OK > Date: Mon, 11 Sep 2006 23:13:05 GMT > Server: Apache/2.2.3 (Unix) > Last-Modified: Sun, 10 Sep 2006 18:21:52 GMT > ETag: "21ac8f5-9d0a-83f57000" > Accept-Ranges: bytes > Content-Length: 40202 > Vary: Accept-Encoding > Connection: close > Content-Type: text/html > > (Hello Mongrel) > $ curl -I http://somedomain.com/go_to/rails/ > HTTP/1.1 200 OK > Date: Mon, 11 Sep 2006 23:13:10 GMT > Server: Mongrel 0.3.13.4 > Status: 200 OK > Cache-Control: no-cache > Content-Type: text/html; charset=utf-8 > Vary: Accept-Encoding > Connection: close > > > > Thanks, > > Martins > > _______________________________________________ > > Mongrel-users mailing list > > Mongrel-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mongrel-users > > > > ==================> Matt Pelletier > EastMedia > t. 212-967-4239 > f. 212-967-4257 > m. 917-902-2525 > w. www.eastmedia.com > > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
Hi! On Mon, Oct 02, 2006 at 09:46:12AM +0300, 13 wrote: [..]> > > RewriteEngine On > > > > > > # Check for maintenance file. Let apache load it if it exists > > > RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f > > > RewriteRule . /system/maintenance.html [L] > > > > > > # Let apache serve static files > > > RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f > > > RewriteRule (.*) $1 [L] > > > > > > # Don''t do forward proxying > > > ProxyRequests Off > > > > > > # Enable reverse proxying > > > <Proxy *> > > > Order deny,allow > > > Allow from all > > > </Proxy> > > > > > > # Pass other requests to mongrel instance > > > ProxyPass / http://127.0.0.1:8200/ > > > ProxyPassReverse / http://127.0.0.1:8200/Are you sure this setup serves static files via Apache? Imho the ProxyPass directives should be executed regardless of the outcome of your rewriting, forwarding all requests to mongrel. I usually use the rewriting the other way around, without any ProxyPass directives: # Don''t do forward proxying ProxyRequests Off # Enable reverse proxying <Proxy *> Order deny,allow Allow from all </Proxy> RewriteEngine On # Check for maintenance file. Let apache load it if it exists RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteRule . /system/maintenance.html [L] # Rewrite index to check for static RewriteRule ^/$ /index.html [QSA] # Let apache serve static files (send everything via mod_proxy that # is *no* static file (!-f) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule .* http://127.0.0.1:8200%{REQUEST_URI} [L,P,QSA] the P option to the last rule replaces the ProxyPass and ProxyPassReverse directives. 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
Hi Jens, Yes I am sure that static files are served by apache. I have checked it using both mongrel debug mode and curl. I''m not sure why would I need to forward requests, for files that apache can serve, to mongrel so I will stay with my configuration until someone proves me wrong. As I said before I''m not an apache expert, but your last rule looks like misuse of mod_rewrite. Isn''t it like that last rewrite rule does what ProxyPass + ProxyPassReverse are supposed to do ? -- Martins On 10/2/06, Jens Kraemer <kraemer at webit.de> wrote:> Hi! > > On Mon, Oct 02, 2006 at 09:46:12AM +0300, 13 wrote: > [..] > > > > RewriteEngine On > > > > > > > > # Check for maintenance file. Let apache load it if it exists > > > > RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f > > > > RewriteRule . /system/maintenance.html [L] > > > > > > > > # Let apache serve static files > > > > RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f > > > > RewriteRule (.*) $1 [L] > > > > > > > > # Don''t do forward proxying > > > > ProxyRequests Off > > > > > > > > # Enable reverse proxying > > > > <Proxy *> > > > > Order deny,allow > > > > Allow from all > > > > </Proxy> > > > > > > > > # Pass other requests to mongrel instance > > > > ProxyPass / http://127.0.0.1:8200/ > > > > ProxyPassReverse / http://127.0.0.1:8200/ > > Are you sure this setup serves static files via Apache? Imho the > ProxyPass directives should be executed regardless of the outcome of > your rewriting, forwarding all requests to mongrel. > > I usually use the rewriting the other way around, without any ProxyPass > directives: > > # Don''t do forward proxying > ProxyRequests Off > > # Enable reverse proxying > <Proxy *> > Order deny,allow > Allow from all > </Proxy> > > RewriteEngine On > > # Check for maintenance file. Let apache load it if it exists > RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f > RewriteRule . /system/maintenance.html [L] > > # Rewrite index to check for static > RewriteRule ^/$ /index.html [QSA] > > # Let apache serve static files (send everything via mod_proxy that > # is *no* static file (!-f) > RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f > RewriteRule .* http://127.0.0.1:8200%{REQUEST_URI} [L,P,QSA] > > > the P option to the last rule replaces the ProxyPass and > ProxyPassReverse directives. > > 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 Mon, Oct 02, 2006 at 02:22:29PM +0300, 13 wrote:> Hi Jens, > > Yes I am sure that static files are served by apache. I have checked > it using both mongrel debug mode and curl. > > I''m not sure why would I need to forward requests, for files that > apache can serve, to mongrel so I will stay with my configuration > until someone proves me wrong.I did not say your config is wrong, just that it''s hard to understand why it works from my limited understanding of apache''s config. Seems like the [L] flag of your last rewrite rule prevents mod_proxy from following the ProxyPass / directive (which, standing for itself, simply says ''proxy everything to mongrel'').> > As I said before I''m not an apache expert, but your last rule looks > like misuse of mod_rewrite. Isn''t it like that last rewrite rule does > what ProxyPass + ProxyPassReverse are supposed to do ?Yes, that was what I wanted to point out - that one line does what your Proxy* directives do. As the [P] flag is officially documented [1], I don''t think it''s use should be called misuse ;-) As your setup works, too, it seems to be more a question of personal preference... Jens [1] http://httpd.apache.org/docs/2.0/misc/rewriteguide.html, look for "Proxy Throughput feature" -- 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