CSS/Javascript 不适用于生产环境

CSS/Javascript Not Applying In Production

本文关键字:适用于 生产环境 不适用 Javascript CSS      更新时间:2023-09-26

我有一个带有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;
            }
    }

正如我所怀疑的那样,CSS(和JS)是在页面之后加载的。我将 nginx 配置中的资产块移到根位置块上方,现在一切正常。