You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bruce Hodo <bc...@earthlink.net> on 2007/09/30 23:42:17 UTC

[users@httpd] Apache 2.0-Mongrel Proxy problems

I've been trying to resolve this for over 2 weeks, but no one seems to 
be able to tell me what's wrong. Maybe you folks can help me.
(this is a copy of a post I made on a Usenet alt.apache.configuration, 
with no responses)

I'm running Ubuntu 6.06LTS, Apache 2.0.55, and WebMin 1.36. I've been
trying to set up static content with server-side includes to be
delivered by Apache, but reverse proxying for Rails application
reqeusts on a local (soon to be remote) Mongrel server at port 8000. I
also wanted to have any request that is received without a specific
file to be redirected to index.shtml.

I've been able to get everything running EXCEPT the reverse proxy with
the following config:

         ServerName myapp.com
         ServerAlias www.myapp.com
         ServerAdmin webmaster@localhost
         DocumentRoot /var/www/rails/myapp/public
         ErrorLog /var/www/myapp/log/apache2.log

         RewriteMap  railservers rnd:/var/www/rails/map.txt
         <Directory /var/www/rails/myapp/public/>
         Options FollowSymLinks +Includes +ExecCGI
         AllowOverride None
                 Order allow,deny
                 Allow from all
                 RewriteEngine On
                 RewriteRule ^$ index.shtml [QSA]
                 RewriteRule 
"^/(images|stylesheets|javascripts|pictures|graphics)/?
(.*)" "$0" [L]
                 RewriteCond %{REQUEST_FILENAME} !-f
                 RewriteRule ^/(.*)$ http://localhost:8000/$1 [P,L]
         </Directory>
         RewriteLog "/var/www/myapp/log/rewrite.log"
         RewriteLogLevel 0
         #placed in global parameter file

         # Avoid open server to proxying
         ProxyRequests Off
         # Pass other requests to mongrel instance
         #ProxyPass / http://localhost:8000/
         # Enable reverse proxying
         ProxyPassReverse / http://localhost:8000/
         # Let apache pass the original host not the ProxyPass one
         ProxyPreserveHost On

         AddType text/html .shtml
         AddOutputFilter INCLUDES .shtml

         LogLevel debug

         CustomLog /var/log/apache2/access.log "combined"
         ServerSignature On

I have a RewriteMap defined to allow me to set up a cluster of
Mongrels once I get one working, since 2.0 doesn't have the balancer
module.

Webmin puts the proxy config in a separate file called proxy.conf
which contains:

<IfModule mod_proxy.c>

         #turning ProxyRequests on and allowing proxying from all may
allow
         #spammers to use your proxy to send email.

         ProxyRequests Off

         <Proxy *>
                 Order deny,allow
                 #Deny from all
                 Allow from all
         </Proxy>

         # Enable/disable the handling of HTTP/1.1 "Via:" headers.
         # ("Full" adds the server version; "Block" removes all outgoing 
Via:
headers)
         # Set to one of: Off | On | Full | Block

         ProxyVia Off

         # To enable the cache as well, edit and uncomment the following
lines:
         # (no cacheing without CacheRoot)

         CacheRoot "/var/cache/apache2/proxy"
         CacheSize 5
         CacheGcInterval 4
         CacheMaxExpire 24
         CacheLastModifiedFactor 0.1
         CacheDefaultExpire 1
         # Again, you probably should change this.
         #NoCache a_domain.com another_domain.edu joes.garage_sale.com

</IfModule>

I've tried several things:
-put the rewriteengine on directive outside of the directory block: I
was unable to access any page that wasn't specifically requested.

-defined "ProxyPass / http://localhost:8000/": was unable to access
anything (no permission to access) even though permissions are set to
775

-turned on rewritelog. here are the results for a www.myapp.com/state/list
request:
(3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
www/rails/myapp/public/state/list
(3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
state/list
(3)  applying pattern '^$' to uri 'state/list'
(3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
www/rails/myapp/public/state/list
(3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
state/list
(3)  applying pattern '^/(images|stylesheets|javascripts|pictures|
graphics)/?(.*)' to uri 'state/list'
(3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
www/rails/myapp/public/state/list
(3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
state/list
(3)  applying pattern '^/(.*)$' to uri 'state/list'
(1)  pass through /var/www/rails/myapp/public/state

It seems that the rewrite is working up to the rewritecond statement.
It parses the statement pattern correctly, but the file state/list
does not exist, so the condition "!-f" should pass the request to
Mongrel, but it seems to pass it to Apache, who doesn't find the file
"state/list" and gives a 404 error, unless I'm reading the logs wrong!
I wish I had detailed instructions on how to read a rewritelog and
what the codes mean. I haven't been able to find them anywhere.

The proxy modules are loaded, so there must be something else I'm not
doing. I've been working on this for 2 weeks. Any suggestions will be
appreciated!

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Apache 2.0-Mongrel Proxy problems

Posted by Joshua Slive <jo...@slive.ca>.
On 9/30/07, Bruce Hodo <bc...@earthlink.net> wrote:

>          <Directory /var/www/rails/myapp/public/>
>          Options FollowSymLinks +Includes +ExecCGI
>          AllowOverride None
>                  Order allow,deny
>                  Allow from all
>                  RewriteEngine On
>                  RewriteRule ^$ index.shtml [QSA]
>                  RewriteRule
> "^/(images|stylesheets|javascripts|pictures|graphics)/?
> (.*)" "$0" [L]
>                  RewriteCond %{REQUEST_FILENAME} !-f
>                  RewriteRule ^/(.*)$ http://localhost:8000/$1 [P,L]
>          </Directory>

> -turned on rewritelog. here are the results for a www.myapp.com/state/list
> request:
> (3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
> www/rails/myapp/public/state/list
> (3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
> state/list
> (3)  applying pattern '^$' to uri 'state/list'
> (3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
> www/rails/myapp/public/state/list
> (3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
> state/list
> (3)  applying pattern '^/(images|stylesheets|javascripts|pictures|
> graphics)/?(.*)' to uri 'state/list'
> (3)  add path info postfix: /var/www/rails/myapp/public/state -> /var/
> www/rails/myapp/public/state/list
> (3)  strip per-dir prefix: /var/www/rails/myapp/public/state/list ->
> state/list
> (3)  applying pattern '^/(.*)$' to uri 'state/list'
> (1)  pass through /var/www/rails/myapp/public/state
>
> It seems that the rewrite is working up to the rewritecond statement.
> It parses the statement pattern correctly, but the file state/list
> does not exist, so the condition "!-f" should pass the request to
> Mongrel, but it seems to pass it to Apache, who doesn't find the file
> "state/list" and gives a 404 error, unless I'm reading the logs wrong!

Yes, you are reading the logs wrong. The fact is, the regular
expression  '^/(.*)$' does not match the uri  'state/list' (no leading
slash). So the RewriteCond is never even evaluated. (I think perhaps
your RewriteLogLevel is set too low, which is why the log is difficult
to interpret.)

My principal recommendation is to take the whole mod_rewrite
configuration outside the <Directory> section. Rewriting inside
<Directory> introduces a whole bunch of extra stripping and adding of
path-prefixes that makes mod_rewrite even more confusing than it would
ordinarily be. You'll need to make some adjustments to the config, but
they should be evident if you use the RewriteLog to check what
variables mod_rewrite is seeing.

And you can come back again here if you still have problems after you
have tried to make all the relevant adjustments.

(Also, if you want to use caching, you should move up to 2.2.)

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org