1

I'm using Apache2 and Passenger to serve my web rails application.

I'm using the asset pipeline of Rails to serve static assets from the Rails.root/public folder. Usually when a request for an asset file is made, Apache2 success to find the corresponding asset file and serve it. I'm happy with that.

But when the asset is missing, Passenger is taking over the request and redirect it to rails. Then Rails is generating a 404 error.

My goal is to prevent Apache/Passenger to redirect to the Rails app if the asset is missing. I'm trying to generate a 404 error without using Rails. I want that as soon as Apache2 fail to get the asset, he send back the error.

I'm using a virtualhost, here is my configuration file. (I'm using SSL) I want the public folder to be serve only with Apache even with the files are missing.

<VirtualHost *:443>
    ServerName DOMAIN_NAME

    DocumentRoot /home/RAILS_APP_PATH/public
    #Here I saw some others configurations files having other directives, maybe I should add one.

    PassengerFriendlyErrorPages On

    RewriteEngine On

    ErrorDocument 503 /503.html
    RewriteCond %{REQUEST_URI} !^/503.html$
    RewriteCond %{DOCUMENT_ROOT}/../tmp/maintenance.txt -f
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /503.html [NC,R=503,L]
    RewriteCond %{DOCUMENT_ROOT}/../tmp/maintenance.txt !-f
    RewriteCond %{REQUEST_URI} ^/503.html
    RewriteRule ^503.html https://DOMAIN_NAME.com/ [R=302,L]

    SSLEngine ON
    SSLCertificateFile /home/SSL_PATH/certificat.crt
    SSLCertificateKeyFile /home/SSL_PATH/certificat.key
    SSLCertificateChainFile /home/SSL_PATH/bundle.crt

</VirtualHost>

1 Answer 1

1

Try this :)

<Location /public>
   PassengerEnabled off
</Location>
1
  • Thanks a lot!! I have to set /assets instead of /public. Jul 30, 2015 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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