rails + nginx + passenger not finding my gemified precompiled assets in production

226 Views Asked by At

My app works fine in development and also in production on my local Mac with config.serve_static_assets = true . However, in production on the Ubuntu 18.04 server I'm getting the following error in NGINX:

No such file to load -- opal_ujs.rb (LoadError)

when I do find . | grep opal_ujs I see the following

./vendor/bundle/ruby/2.5.0/gems/opal-rails-0.9.5/lib/assets/javascripts/opal_ujs.js.rb
./public/assets/opal_ujs-a633a78701574b25c28a62e6892b2a6f2cb93afcd9b71edc9bf5eea75a296481.js.gz
./public/assets/opal_ujs-a633a78701574b25c28a62e6892b2a6f2cb93afcd9b71edc9bf5eea75a296481.js

OK so it's there. Why isn't it being served. The relevant production.rb snippet is as follows:

  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.compile = true
  config.serve_static_assets = false
  config.assets.digest = true

My setup is Phusion Passenger + NGINX. And my NGINX server config for the app has gone through a number of trials but currently is as follows, which another attempt commented out:

server {
        listen 80;
        listen [::]:80;

        server_name myapp.domain;
        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/myapp/current/public;

        # Allow uploads up to 100MB in size
        client_max_body_size 100m;

        #location ~ ^/(assets|packs) {
        # expires max;
        # gzip_static on;
        #}

        # Rails asset pipeline support.

        location ~ ^/assets/ {
          root         /home/deploy/myapp/current/public;
          gzip_static on; # to serve pre-gzipped version
          expires max;
          add_header Cache-Control public;

          # add_header ETag "";
          break;
        }
        # Rails asset pipeline support.
#       location ~ "^/assets/.+-([0-9a-f]{32}|[0-9a-f]{64})\..+" {
#           error_page 490 = @static_asset;
#           error_page 491 = @dynamic_request;
#           recursive_error_pages on;

#           if (-f $request_filename) {
#               return 490;
#           }
#           if (!-f $request_filename) {
#               return 491;
#           }
#       }
#       location @static_asset {
#           gzip_static on;
#           expires max;
#           add_header Cache-Control public;
#           add_header ETag "";
#       }
#       location @dynamic_request {
#           passenger_enabled on;
#       }
}

what am I doing wrong here?

1

There are 1 best solutions below

1
LiKaZ On

You try to load a file named

opal_ujs.rb

and you have this files :

opal_ujs.js.rb

and in assets

opal_ujs-xxxxx.js

maybe it's not the same file.