我有一个带有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;
}
}
答案 0 :(得分:0)
正如我所怀疑的那样,CSS(和JS)在页面被加载之后被加载。我将nginx配置中的资产块移动到根位置块上方,现在情况正常。