我有一个带有 CSS/JS 的 Rails 应用程序,在开发中运行良好。在生产中,资产的预编译运行良好。资源位于正确的位置,据我所知,一切都已正确链接。
问题是,尽管这些文件中有看似正确的 CSS,但它实际上并没有应用到页面上。如果我进入编辑器,剪切所有已编译的 CSS 并重新粘贴它,它的工作原理是什么。然后所有的 CSS 都适用。
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 = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :debug
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
nginx.conf partial
server {
listen 80 default;
server_name example.com;
root /home/appuser/current/public;
# access_log /var/log/nginx/access.log;
rewrite_log on;
location / {
#all requests are sent to the UNIX socket
proxy_pass http://example;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ ^/assets/ {
root /home/appuser/current/public;
gzip_static on;
expires max;
add_header Cache_Control public;
}
}