4

I deployed a Rails 3.2.8 application via Capistrano, with asset pipeline enabled, to my Linode server.

It is running nginx + unicorn.

When I visit my application, the minimised JS and CSS are not being served, although the assets are present in <RAILS_DIR>/public/assets.

$ tree assets
assets
|-- application-66e477d6fd8cf088e8be44affeead089.css
|-- application-66e477d6fd8cf088e8be44affeead089.css.gz
|-- application-7d3ead38a0b5e276a97d48e52044ac31.js
|-- application-7d3ead38a0b5e276a97d48e52044ac31.js.gz

In my application, I can see those exact files not being found:

error

This is my nginx configuration:

server {
  listen 80 default deferred;
  server_name me.example.com;
  root /home/kennym/apps/app/current/public;

  location ^~ /assets/ {
    add_header Last-Modified "";
    add_header ETag "";
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

Can you guess what is wrong?

3 Answers 3

9

location ^~ /assets/ should be location ~ ^/assets/.

The former is does not match /assets/, the latter is matches a pattern that starts with /assets/

Update your nginx config to get caching and pre-gzipped file serving working again.

Sign up to request clarification or add additional context in comments.

Comments

3

I fixed this by commenting out the location ^~ /assets/ block in the nginx.conf.

2 Comments

This is ok only when you want rails server to hanlde the static files instead of nginx. Kind of defeats the purpose of nginx if thats only what you're using it for.
agreed... it's kind of a hack.
1

For those having the same issue, for me the solution was to go into /etc/nginx/conf.d/default.conf and set the root field correctly.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.