rails - nginx + puma - static assets not being served by nginx from the tutorial link provided

Viewed 6147

I am using Ubuntu. Here is the tutorial

Nginx config I am using:

upstream my_app {
server unix:///home/uname/railsproject/my_app.sock;
}

server {
listen 88; #(I used exact 88 when I am testing now)
server_name localhost; # I used exact localhost when I am testing this
root /home/uname/railsproject/public; # I assume your app is located at that location

location / {
 proxy_pass http://my_app; # match the name of upstream directive which is defined above
 proxy_set_header Host $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~* ^/assets/ {
 # Per RFC2616 - 1 year maximum expiry
 expires 1y;
 add_header Cache-Control public;

 # Some browsers still send conditional-GET requests if there's a
 # Last-Modified header or an ETag header even if they haven't
 # reached the expiry date sent in the Expires header.
 add_header Last-Modified "";
 add_header ETag "";
 break;
 }

}

Puma command

RAILS_ENV=production puma -e production  -b unix:///home/uname/railsproject/my_app.sock -p 8000

In the address bar, I am typing

http://localhost/ 

and then website opening but static assets not working. Of course, I ran

RAILS_ENV=production rake assets:precompile

and assets are available in public/assets folder
I also tried placing m.txt file in assets directory and accessing

http://localhost/assets/m.txt    

but didn't work. I also tried this command:

sudo chown -R www-data:www-data public/

but this didn't help.

2 Answers
Related