I am trying to configure Nginx + Rails + Puma with unix sockets but I was not able to serve my asests. I have following configurations I would appreciate if someone could point what is missing. My Nginx configuration;
upstream my_app {
server unix:///var/run/my_app.sock;
}
server {
listen 8080;
server_name _;
root /var/www/plantmonitorweb/public; # app location
location / {
proxy_pass http://my_app;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# this one is from Rails guides
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
}
}
In production.rb
config.public_file_server.enabled = false
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
puma.rb is not changed. I am running puma server with following command;
puma -e production -b unix:///var/run/my_app.sock
I run those in remote machine (Rasberry Pi to be specific) Puma runs fine it seems nginx is hitting my server but when I open chorome console I see following
GET http://192.168.1.35:8080/pack/app.js
I check this file under public/pack and it is there.
My Nginx configuration is in /etc/nginx/conf.d/ which is included inside of Nginx.conf (include /etc/nginx/conf.d/*.conf)
In rails 5, react js files are served under public/pack/
. So we need to add those locations to be served statically as well as assets folder. So added following location to my nginx configuration.
location ~ ^/(assets|packs)/ {
gzip_static on;
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With