# Apache, Mongrel, Authentication

**URL:** <https://www.ruby-forum.com/t/apache-mongrel-authentication/126937>\
**Category:** Mongrel\
**Created:** [January 23, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937 "2008-01-23T16:12:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [January 23, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/1 "2008-01-23T16:12:40Z")

</div>

A question about mongrel, apache and authentication.

I’ve got a Rails site with I think a very typical setup: a mongrel  
cluster behind an Apache proxy. So Apache’s handling the static stuff  
and it hands off dynamic content to mongrel. I want to put the site  
temporarily behind Apache’s basic authentication. What I get when I  
do this is that is a password prompt which prevents all of the images,  
stylesheets and other static files from being loaded unless  
authenication passes, but anything mongrel handles is not.  
Specifically, a user can just keep hitting “Cancel” at the  
browser-generated password prompt and he/she will see that rails  
generated content without ever entering any credentials. No styling  
and no images, but they do see content. How can I fix it? Mongrel  
does not seem to be honoring the authentication (and frankly, I don’t  
know if it can). Here’s my apache config:

\<VirtualHost \*:80\>  
ServerAdmin removed\_email\_address@domain.invalid  
DocumentRoot /www/mysite/current/public  
ServerName [www.mysite.com](http://www.mysite.com)  
ErrorLog /www/mysite/logs/mysite.error.log  
CustomLog /www/mysite/logs/mysite.access.log combined

\<Directory “/www/mysite/current/public”\>  
Options FollowSymLinks  
AllowOverride AuthConfig Limit  
Order allow,deny  
Allow from all

```
  AuthType Basic
  AuthName "Restricted"
  AuthBasicProvider file
  AuthUserFile /www/mysite/users/userdb
  Require valid-user

```

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]

# 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://mongrel\_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

\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:8000](http://127.0.0.1:8000)  
BalancerMember [http://127.0.0.1:8001](http://127.0.0.1:8001)  
BalancerMember [http://127.0.0.1:8002](http://127.0.0.1:8002)

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [January 23, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/2 "2008-01-23T16:24:25Z")

</div>

You need put password directives in proxy balancer:

\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:8000](http://127.0.0.1:8000)  
BalancerMember [http://127.0.0.1:8001](http://127.0.0.1:8001)  
BalancerMember [http://127.0.0.1:8002](http://127.0.0.1:8002)  
AuthType Basic  
AuthName “Restricted”  
AuthBasicProvider file  
AuthUserFile /www/mysite/users/userdb  
Require valid-user

Regards

Sean B. escribiÃ³:

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [August 29, 2008, 11:07am UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/3 "2008-08-29T11:07:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [August 29, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/4 "2008-08-29T13:08:32Z")

</div>

Antoine Antoine escribiÃ³:

> 

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](http://127.0.0.1:8008)  
AuthType Basic  
AuthName “foo authentication”  
AuthUserFile /usr/local/apache2/conf/passwords  
Require user bar

\<VirtualHost \*:80\>  
ServerName [foo.com](http://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

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

=== /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

```

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [August 29, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/5 "2008-08-29T18:56:51Z")

</div>

Antoine Antoine escribiÃ³:

> * * *
> 
> Maybe that’s due to my \<proxy \*\> in front of it no ?

It could be because apache read config files sequentially and maybe give  
priority to proxy \* but I don’t know really.

Try to comment it.

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [August 29, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/6 "2008-08-29T14:52:13Z")

</div>

Thanks rafael for your fast reply,

But I tried to apply that and I still have the problem. Here is my  
situation.

* * *

\<Proxy \*\>  
Options Indexes FollowSymLinks MultiViews  
AllowOverride All  
Order Allow,Deny  
Allow from all  
Deny from env=blockAccess  
AcceptPathInfo Off  
Satisfy Any

\<VirtualHost \*:80\>  
ServerName [my.servername.com](http://my.servername.com)  
… # this virtual host doesn’t have anymore authentication

# and with mongrel\_cluster …

\<VirtualHost \*:80\>  
ServerName [my.servername.com](http://my.servername.com)  
…  
DocumentRoot /…/public/

\<Directory /…/public/ \>  
Options Indexes FollowSymLinks MultiViews  
AllowOverride All  
Order Allow,deny  
Allow from all  
Deny from env=blockAccess  
AuthType Basic  
AuthName “Version Foo”  
AuthUserFile “/mypath/to/.htpasswd”  
require valid-user

\<Proxy balancer://my.server\_cluster\>  
BalancerMember [http://localhost:4000](http://localhost:4000)  
AuthType Basic  
AuthName “Version Foo”  
AuthUserFile “/mypath/to/.htpasswd”  
require valid-user

[…]

* * *

Maybe that’s due to my \<proxy \*\> in front of it no ?

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [October 23, 2008, 10:42am UTC](https://www.ruby-forum.com/t/apache-mongrel-authentication/126937/7 "2008-10-23T10:42:50Z")

</div>

Please try using the following in your apache httpd.conf file.

ProxyPass / balancer://balancer-manager/  
ProxyPassReverse / balancer://balancer-manager/  
ProxyPass images balancer://balancer-manager/images  
ProxyPass javascripts balancer://balancer-manager/javascripts  
ProxyPass stylesheets balancer://balancer-manager/stylesheets

in virtualhost block.
