Assets not serviced by RoR 4, Nginx, Unicorn

I deployed the RoR 4 application using Capistrano 2, Unicorn, Nginx. The problem is that I get 404 by assets (style sheets, javascripts).

Here is the Nginx access log:

89.0.40.233 - - [16/Mar/2014:08:24:26 +0000] "GET /stylesheets/application.css HTTP/1.1" 404 650 "http://host.cloudapp.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" 89.0.40.233 - - [16/Mar/2014:08:24:26 +0000] "GET /javascripts/application.js HTTP/1.1" 404 650 "http://host.cloudapp.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" 

My assets are located in the application folder:

 azureuser@host :~/apps/testify/current/public$ ls -a assets . application-d65a0eaefe6ca2eef9400045f94ab52b.js .. application-d65a0eaefe6ca2eef9400045f94ab52b.js.gz application-71e2591e9586afebf3fb4ff70aaae199.css manifest-a348973e84698f7d898e8021bd6e5388.json application-71e2591e9586afebf3fb4ff70aaae199.css.gz 

My Nginx config:

 upstream unicorn { server unix:/tmp/unicorn.testify.sock fail_timeout=0; } server { listen 80 default deferred; root /home/azureuser/apps/testify/current/public; location ^~ /assets/ { 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; } 

Where to begin?

+6
source share
4 answers

As seen from access.log, you just encoded application.css / .js in your layout. There are no such files in the shared folder due to the fingerprint name that gives them the resource pipeline (look at your ls output example).

You can read about it here .

Fixing your problem is very simple. Replace hardlinked links for application.css / .js with this code:

 <%= javascript_include_tag "application" %> <%= stylesheet_link_tag "application" %> 
+9
source

Adding to the answer of Sergey Moiseyev

Try to get the data directly with the URL / assets / javascripts / application -d65a0eaefe6ca2eef9400045f94ab52b.js.If it doesn’t work, your problem is in nginx and not on the rails.

Also check if you are extracting the file with the correct fingerprint. In this case, check his application-d65a0eaefe6ca2eef9400045f94ab52b.js or another application.js application with a different fingerprint. I got a similar problem with multiple servers.

+1
source

For me, the root path was wrong in my nginx configuration, and I ran into this exact problem. Link: fooobar.com/questions/965827 / ...

0
source

I would suggest that Capistrano does not use "production" as the environment name for Unicorn (-E option). "ps aux | grep unicorn" will probably tell you which environment it uses.

-1
source

All Articles