Rails,EC2,Nginx,Unicorn-新资产不再在生产中呈现

时间:2018-10-19 17:33:11

标签: ruby-on-rails nginx amazon-ec2

我添加的新资产不再显示在生产站点上(在EC2上)。以前可以使用,并且较旧的图像,样式表和.js文件也可以使用,但是我添加的所有新内容都无法呈现。

我跑步时

rake assets:precompile RAILS_ENV="production" 

我得到以下消息,没有错误:

yarn install v1.9.4
warning package-lock.json found. Your project contains lock files    generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by  unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.09s.

但是在我的nginx错误日志中,最近添加的所有我的资产都有一系列错误,如下所示:

2018/10/19 16:59:13 [error] 5875#5875: *9800 open() "/home/deploy/production/
{appname}/public/assets/images/social.svg" failed (2: No such file or directory), 
client: xx.x.xxx.xxx, server: , request: "GET /assets/images/social.svg HTTP/1.1", 
host: "{appname}.com", referrer: "http://{appname}.com/"

我不是最初设置此问题的人,也不清楚导致问题的原因,如果有人能向我指出正确的方向,我将不胜感激。我一直在阅读可以找到的所有内容,但是却一无所获。

production.rb

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.read_encrypted_secrets = true

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

  config.assets.paths << "#{Rails.root}/assets/fonts"
  config.assets.paths << "#{Rails.root}/assets/images"
  config.assets.paths << "#{Rails.root}/assets/javascripts"
  config.assets.paths << "#{Rails.root}/assets/stylesheets"
  config.assets.paths << "#{Rails.root}/assets/pdf"

  #config.assets.precompile =  ['*.js', '*.css', '*.css.erb', '*.css.scss' '*.svg' '.png' '.jpg']
  #config.assets.precompile += %w( .svg .eot .woff .ttf .png )
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  config.force_ssl = false
  config.log_level = :debug
  config.log_tags = [ :request_id ]
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "byc1_#{Rails.env}"
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  config.log_level = :info
  RAILS_DEFAULT_LOGGER = Logger.new('log/production.log')  
  config.active_record.dump_schema_after_migration = false

end

/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
  worker_connections 768;
}

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  ssl_prefer_server_ciphers on;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  gzip on;
  gzip_disable "msie6";

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

/ etc / nginx / sites-enabled / bcrypto

upstream bcrypto_unicorn {
    server unix:/home/deploy/production/{appname}/tmp/sockets/bcrypto_unicorn.todo.sock fail_timeout=0;
}

server {
    listen 80 default deferred;
    root /home/deploy/production/{appname}/public;

    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
        add_header ETag "";
    }

    try_files $uri/index.html $uri @bcrypto_unicorn;

    location @bcrypto_unicorn {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://bcrypto_unicorn;
    }

    error_page 422 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 60;
}

config / initializers / assets.rb

Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w( alphabetical_paginate.js )
Rails.application.config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/

0 个答案:

没有答案