[Mongrel] Apache, Mongrel, Authentication

Rafael G. rgo at aspgems.com
Fri Aug 29 06:38:28 EDT 2008


Antoine Antoine escribió:
> Hello Sean,
>
> Did this solution  in the proxy balancer posted by rafael worked for you 
> ? because it seems that applying that, I have no authentication anymore 
> ....
> Did you find any solution for this problem ?
>
> Regards,
>
> Antoine
>
>
>   
Hi Antoine,

    When you want protect an application with basic authentication you 
need protect the static content (served by apache) and dinamic content 
(served by mongrel).

A complete example:

==== foo.conf (vhost config file)

<Proxy balancer://foo_cluster>
    BalancerMember http://127.0.0.1:8008
    AuthType Basic
    AuthName "foo authentication"
    AuthUserFile /usr/local/apache2/conf/passwords
    Require user bar
</Proxy>

<VirtualHost *:80>
   ServerName foo.com
   ServerAlias *.foo.com

  DocumentRoot /home/foo/current/public
   <Directory "/home/foo/current/public">
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
     AuthType Basic
     AuthName "foo"
     AuthUserFile /usr/local/apache2/conf/passwords
     Require user bar
   </Directory>

  RewriteEngine On

  # Check for maintenance file and redirect all requests
  #  ( this is for use with Capistrano's disable_web task )
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]

  # Redirect all non-static requests to cluster
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !\.
  RewriteCond %{REQUEST_FILENAME} (^[^\.]*$)|(.format:js)
  RewriteRule ^/(.*)$ balancer://foo_cluster%{REQUEST_URI} [P,QSA,L]

  # Deflate
  AddOutputFilterByType DEFLATE text/html text/plain text/css
  # ... text/xml application/xml application/xhtml+xml text/javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</VirtualHost>

=== /usr/local/apache2/conf/passwords
passwords file is created:

    # htpasswd -c /usr/local/apache2/conf/passwords bar

Add new user:

    # htpasswd /usr/local/apache2/conf/passwords baz


-- 
Rafael Garcia Ortega

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rgo.vcf
Type: text/x-vcard
Size: 241 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/mongrel-users/attachments/20080829/0e99cd62/attachment.vcf>


More information about the Mongrel-users mailing list