Apache / Unicorn: how to get Apache to serve static files

apache-2.2mod-rewriteunicorn

I'm following this tutorial to install apache + unicorn but it seems that apache doesn't serve any of the static files. Here's the config I came up with (take a look at Redirect all non-static requests to unicorn in particular):

<VirtualHost *:80>
  ServerName www.unstilted.com:80
  ServerAlias *.unstilted.com
  DocumentRoot /var/www/unstilted/current/public

  ErrorDocument 503 /system/maintenance.html

  RewriteEngine On

  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{REQUEST_FILENAME} !/system/maintenance.html
  RewriteRule ^.*$    /system/maintenance.html [L]

  # Rewrite to check for Rails non-html cached pages (i.e. xml, json, atom, etc)
  RewriteCond  %{THE_REQUEST} ^(GET|HEAD)
  RewriteCond  %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_URI} -f
  RewriteRule  ^(.*)$ /cache/%{HTTP_HOST}$1 [QSA,L]

  # Rewrite to check for Rails cached html page
  RewriteCond  %{THE_REQUEST} ^(GET|HEAD)
  RewriteCond  %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_URI}.html -f
  RewriteRule  ^(.*)$ /cache/%{HTTP_HOST}$1.html [QSA,L]

  # no www
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1$1 [R=301,L]

  <Proxy balancer://unicornservers>
    BalancerMember http://127.0.0.1:5000
  </Proxy>

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

  ProxyPass / balancer://unicornservers/
  ProxyPassReverse / balancer://unicornservers/
  ProxyPreserveHost on

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

In my /var/www/unstilted/current/public directory I have robots.txt, but when I go to mydomain.com/robots.txt, the request goes to unicorn, and it's not handled by apache.

What's wrong with my config? And how do I get Apache to serve the static files?

Thanks!

Best Answer

Lose the %{DOCUMENT_ROOT} on that condition. %{REQUEST_FILENAME} is the full filesystem (not URL) path to the file, so it should be matchable like this:

RewriteCond %{REQUEST_FILENAME} !-f