CSS does not load into production - everything is fine in dev (Rails 4.1, Capistrano 3, bootstrap), update: nginx config problem

The problem is this: everything works fine in development, but when I deploy the rails application for production, the site works in plain html, but CSS (bootstrap) doesn't load (JS probably doesn't either).

Sorry, I was looking for 2 days on ~ 15 possible solutions and could not get it to work ...

Update: After you follow @ rich-peck's advice, this seems like a server issue. Updated using nginx configuration

My setup:

  • Ruby 2.1.2, Rails 4.1
  • Rbenv
  • mysql2 as db
  • Bootstrap 3
  • Ubuntu 14.04 on a server with nginx and passenger
  • Capistrano 3 for deployment

Configure as follows - production.rb:

config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_custom_path, '/home/deploy/.rbenv/'
set :rbenv_ruby, '2.1.2'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

in application.rb:

...
# Enable the asset pipeline
config.assets.enabled = true
...

application.css.scss:

/* ...
*= require_self
*= require_tree .
*/

@import "bootstrap";
@import "custom";
@import "exchange_rates";
@import "contacts";

, ( ):

# on dev machine and server /current:
RAILS_ENV=production bundle exec rake assets:precompile

. CSS Javascript Rails

:

config.serve_static_assets = true # tried false
config.assets.compile = false     # tried true

. rails css/js/images

production.log , js.

Rails Asset Pipeline nginx, ... !

: nginx

gorails: https://gorails.com/deploy/ubuntu/14.04

nginx , ( SO) :

/etc/nginx/nginx.conf:

events {
  worker_connections  4096;  ## Default: 1024
}

http {
    ##
    # Phusion Passenger
    ##
    # Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise
    ##
    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /home/deploy/.rbenv/shims/ruby;
    passenger_nodejs /usr/bin/nodejs;
    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;

            server_name <URL>;
            passenger_enabled on;
            rails_env    production;
            root         /home/deploy/<PROJECT_NAME>/current/public;

            # redirect server error pages to the static page /50x.html
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    }
}

(URL PROJECT_NAME )

/etc/nginx/sites-enabled/default , nginx - . - - ?

+1
2

:

  • , public?

precompile , , Rails public. , ,

rake assets:precompile RAILS_ENV=production, public, ,

-

  • public, ?

SSH public ( /current). , .

, Capistrano; , , Rails

-

  • public , , -

, , , - . apache service reload apache2, nginx.

Rails - assets, config?

+4

, Nginx /etc/nginx/sites -available/default, , /etc/nginx/sites - / .

/etc/nginx/nginx.conf, , .

, .

+1

All Articles