ruby 精简Web服务器将预编译资产加载为0字节

bf1o4zei  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(177)

我有一个Rails 7.0应用程序,nginx正在从一个docker容器中提供服务。我使用Sprockets和Esbuild将这些资产捆绑到application.css和application.js中,并将它们消化为public/assets/application-<hash>.csspublic/assets/application-<hash>-.js
这工作得很好,我在Docker容器public/assets中找到的资产有一些类型的内容(消化,所以很难阅读)。
奇怪的是,这些资产是通过Thin(我的Rails包括Web服务器)提供给浏览器的,但这些资产文件的字节数为零。这包括application-<hash>.cssapplication-<hash.js文件,以及所有图像。
我想指出的另一件事是,这个应用程序是在我的docker容器上本地运行的,所以它与Nginx无关。
这很奇怪。这是我的分段配置供参考,有什么想法吗?

# Settings specified here will take precedence over those in config/application.rb

  # Configures whether Rails should serve static files from the public directory.
  config.public_file_server.enabled = true

  # Configures whether all registered config.eager_load_namespaces should be loaded at compile-time. This includes your application, engines, Rails frameworks and any other registered namespace.
  config.eager_load = true

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

  # Configures whether or not to show helpful development messages on error
  config.consider_all_requests_local = false

  # Enable fragment caching (https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching)
  config.action_controller.perform_caching = true

  # Configures Rails itself to serve static files
  config.serve_static_files = false

  # Compress javascripts and css
  config.assets.compress = true

  # Specify whether or not to fall back to Sprockets if precompiled assets aren't loaded
  config.assets.compile = false

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

  # Send logs to Docker STDOUT
  config.logger = Logger.new('/proc/1/fd/1')

  # Doesn't actually send mail
  config.action_mailer.perform_deliveries = false

  # The production environment is meant for finished, "live" apps.
  # Code is not reloaded between requests
  config.cache_classes = true

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

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

  # 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

  config.action_mailer.raise_delivery_errors = false

字符串

kdfy810k

kdfy810k1#

问题出在台词上:

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

字符串
根据官方Rails文档中关于x_sendfile_header的说明,这将拦截从文件提供的主体,并将其替换为服务器特定的X-Sendfile头。
没有太多的潜水,这可能与Nginx而不是Rails服务资产有关,这不是我正在做的。
无论哪种方式,删除此选项都会导致浏览器接收到包含我希望从public/获取的内容的文件

相关问题