Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
I'm not sure but does it work when you remove the ProxyPass*-directives? –  vstm Oct 2 '11 at 15:58

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer
    
Thank you Shane. I tried different combinations but I must have gotten confused and didn't try this. –  Ramon Tayag Oct 3 '11 at 15:13
    
This doesn't solve it for me. –  Rob May 6 '12 at 22:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.