由于某些原因,Active Storage映像未完全加载:Image Not Loading
我正在运行Ruby 3.0.5和Rails 7.0.5
我用这个命令启动我的rails应用程序:
RAILS_ENV=production /usr/share/rvm/wrappers/ruby-3.0.5/rails server -b /var/www/***/puma.sock
字符串
下面是我的Rails环境:
require "active_support/core_ext/integer/time"
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
config.assets.compile = true
config.log_level = :info
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.report_deprecations = false
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.active_storage.service = :local
config.active_storage.variant_processor = :mini_magick
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: '***.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
port: 587,
domain: '***.com',
address: 'mail.***.com',
user_name: ENV['EMAIL_USER'],
password: ENV['EMAIL_PWD'],
authentication: 'plain',
enable_starttls_auto: true
}
config.serve_static_assets = false
config.assets.compress = true
end
型
使用nginx作为代理,这是我的nginx配置:
upstream app {
server unix:///var/www/***/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name ***.com www.***.com;
return 302 https://***.com$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name ***.com www.***.com;
include snippets/ssl-certs.conf;
include snippets/ssl-params.conf;
# Ruby configuration
root /var/www/***/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_read_timeout 120;
}
location ~ ^/(500|404|422).html {
root /var/www/***/public;
}
error_page 500 502 503 504 /500.html;
error_page 404 /404.html;
error_page 422 /422.html;
client_max_body_size 4G;
keepalive_timeout 30;
}
型
我试着在没有nginx的情况下运行应用程序,只使用以下命令
rails s -b 0.0.0.0 -e production
型
图像加载正确
再次在nginx中运行,我尝试使用以下命令更改rails主动存储模式:
config.active_storage.resolve_model_to_route = :rails_storage_proxy
型
但它什么也没做
1条答案
按热度按时间tjrkku2a1#
我看了浏览器中的请求。我收到这些错误:
Firefox中的
NS_ERROR_NET_PARTIAL_TRANSFER
net::ERR_HTTP2_PROTOCOL_ERROR 200
chrome请求的总时间为350ms,这导致我使用这个位置块禁用代理缓冲:
字符串
这样就解决了问题