1

지난 몇 시간 동안 서버를 실행하려고했습니다. 나는 nginx와 레일 승객을 사용하고 있습니다.CSS가로드되지 않습니다. nginx

내 공용/assets 폴더에 미리 컴파일 된 모든 애셋이 있습니다. 로고와 같이 3464deb64640aad071fa1f29714cb888.png와 같은 문자열이 추가되어 고유 식별자로 추측됩니다.

브라우저에서 내 앱으로 이동해도 이미지 나 CSS가로드되지 않습니다. 레일스는 ID 문자열없이 css 파일을로드하려고 시도하는 것 같습니다. 비록 자산 폴더에이 문자열이 있지만 .JS가로드하는 것이 이상하다는 것은 이상합니다.

원본 소스 : 브라우저에서

<!-- Always force latest IE rendering engine or request Chrome Frame --> 
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> 

<!-- Use title if it's in the page YAML frontmatter --> 
<title>1</title> 

<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> 

<!-- Stylesheets --> 
<%= stylesheet_link_tag "application" %> 

<!--csrf meta tags--> 
<%= csrf_meta_tag %> 

<!-- Jquery --> 
<script src="//code.jquery.com/jquery.js"></script> 

<!-- Latest compiled and minified JavaScript --> 
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 

<!--default javascript--> 
<%= javascript_include_tag "application" %> 

출처 :

<!-- Always force latest IE rendering engine or request Chrome Frame --> 
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> 

<!-- Use title if it's in the page YAML frontmatter --> 
<title>1</title> 

<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> 

<!-- Stylesheets --> 
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" /> 


<!--csrf meta tags--> 
<meta content="authenticity_token" name="csrf-param" /> 
<meta content="+wxNNUVYmfRwayYxYOfVLWUEpm+iTH5BZN4Puluebh0=" name="csrf-token" /> 

<!-- Jquery --> 
<script src="//code.jquery.com/jquery.js"></script> 

<!-- Latest compiled and minified JavaScript --> 
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 

<!--default javascript--> 
<script src="/assets/application-e5001548de09f8867b4c904b1630d600.js"></script> 
,451,515,

구성 :

FwnApp::Application.configure do 
# Settings specified here will take precedence over those in config/application.rb. 

# Code is not reloaded between requests. 
config.cache_classes = true 

# Eager load code on boot. This eager loads most of Rails and 
# your application in memory, allowing both thread web servers 
# and those relying on copy on write to perform better. 
# Rake tasks automatically ignore this option for performance. 
config.eager_load = true 

# Full error reports are disabled and caching is turned on. 
config.consider_all_requests_local  = false 
config.action_controller.perform_caching = true 

# Enable Rack::Cache to put a simple HTTP cache in front of your application 
# Add `rack-cache` to your Gemfile before enabling this. 
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. 
# config.action_dispatch.rack_cache = true 

# Disable Rails's static asset server (Apache or nginx will already do this). 
config.serve_static_assets = false 

# Compress JavaScripts and CSS. 
config.assets.js_compressor = :uglifier 
# config.assets.css_compressor = :sass 

# Do not fallback to assets pipeline if a precompiled asset is missed. 
config.assets.compile = false 

# Generate digests for assets URLs. 
config.assets.digest = true 

# Version of your assets, change this if you want to expire all your assets. 
config.assets.version = '1.0' 

# Specifies the header that your server uses for sending files. 
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
# config.force_ssl = true 

# Set to :debug to see everything in the log. 
config.log_level = :info 

# Prepend all log lines with the following tags. 
# config.log_tags = [ :subdomain, :uuid ] 

# Use a different logger for distributed setups. 
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 

# Use a different cache store in production. 
# config.cache_store = :mem_cache_store 

# Enable serving of images, stylesheets, and JavaScripts from an asset server. 
# config.action_controller.asset_host = "http://assets.example.com" 

# Precompile additional assets. 
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 
# config.assets.precompile += %w(search.js) 

# Ignore bad email addresses and do not raise email delivery errors. 
# Set this to true and configure the email server for immediate delivery to raise  delivery errors. 
# config.action_mailer.raise_delivery_errors = false 

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
# the I18n.default_locale when a translation can not be found). 
config.i18n.fallbacks = true 

# Send deprecation notices to registered listeners. 
config.active_support.deprecation = :notify 

# Disable automatic flushing of the log to improve performance. 
# config.autoflush_log = false 

# Use default logging formatter so that PID and timestamp are not suppressed. 
config.log_formatter = ::Logger::Formatter.new 
end 

require File.expand_path('../boot', __FILE__) 

require 'rails/all' 

# Require the gems listed in Gemfile, including any gems 
# you've limited to :test, :development, or :production. 
Bundler.require(:default, Rails.env) 

module FwnApp 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    # config.i18n.default_locale = :de 
    end 
end 

응용 프로그램 CSS

/* 
*= require_self 
*= require_tree . 
*/ 

응용 프로그램 RB

require File.expand_path('../boot', __FILE__) 

require 'rails/all' 

# Require the gems listed in Gemfile, including any gems 
# you've limited to :test, :development, or :production. 
Bundler.require(:default, Rails.env) 

module FwnApp 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    # config.i18n.default_locale = :de 
    end 
end 

답변

1

설정 true에 :

config.serve_static_assets = true 
config.assets.compile = true 

여전히 작동하지 않으면 application.rbapplication.css 개의 파일을 공유하십시오.

  1. application.css 매니페스트에 추가 :

    편집

    는 두 가지 옵션이 다른 CSS 파일을 추가합니다.

  2. application.rb에서 : config.assets.precompile += ['application.css', 'other.css']

어떻게 자산 파이프 라인 작품을 이해하기 위해 레일 guides을 읽어보실 것을 권장합니다.

응용 프로그램 레이아웃, 페이지에 따라 추가하려면

application.html.haml 어떤 ​​관점에서 그런

... 
= yield :css if content_for?(:css) 
... 

:

view.html.HAML는

- content_for :css do 
    stylesheet_link_tag 'other' 

2에로 other.css를 추가해야합니다.

+0

일은 내가 nginx와 함께 일하기를 원합니다. 그래서 nginx에서 자산을 전달하고 serve_static_assets에 대신 레일을 제공 할 것입니다. – Melbourne2991

+0

당신 말이 맞아요. 그래서 파일을 공유하십시오. – cortex

+0

파일을 추가했습니다. 나는 그저 일어난 일을보기 위해 위의 두 가지 설정을 변경합니다. 문자열이 CSS 파일에 추가되었지만 여전히 404d입니다. – Melbourne2991

관련 문제