I am currently using Apache to proxy to Thin (using this article)
None of my static assets work (e.g. stylesheets, javascripts). Is Apache supposed to be serving them or do I have to enable config.serve_static_assets
in config/environments/production.rb
? If Apache is supposed to serve them, then what am I probably doing wrong?
Here is my Apache config:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/r/public_html/example/public
RewriteEngine On
<Proxy balancer://thinservers>
BalancerMember http://127.0.0.1:5000
BalancerMember http://127.0.0.1:5001
BalancerMember http://127.0.0.1:5002
</Proxy>
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /home/r/public_html/example/log/error.log
CustomLog /home/r/public_html/example/log/access.log combined
</VirtualHost>
Delete the following two proxy directive lines and it should work:
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
The first rewrite line (RewriteCond
) is a test to see if the file exists on the filesystem in the public directory. If it fails, it continues to the next rewrite line (RewriteRule
), which passes the request to the balanced proxy. This line actually does much the same thing as the two proxy directive lines.
If the test succeeds (i.e the static file exists), it'll skip this line. If you've removed the two lines above, apache would then serve the file from the document root. However, with the lines above in, it'll just end up passing it over to the proxy anyway. Then as you pointed out, rails won't be configured to serve this file by default and will return a 404.