Elastic Beanstalk Passenger-Standalone Rails 不提供静态资产

Posted

技术标签:

【中文标题】Elastic Beanstalk Passenger-Standalone Rails 不提供静态资产【英文标题】:Elastic Beanstalk Passenger-Standalone Rails not serving static assets 【发布时间】:2014-08-26 03:52:16 【问题描述】:

当我使用 aws.push 部署我的 rails 4.1 应用程序时,它不服务于我的任何静态资产。一切正常,但没有 css、javascript 或图像。

当我尝试运行时:

RAILS_ENV=production bundle exec rake assets:precompile

我收到此错误:

rake aborted!
Sass::SyntaxError: Invalid CSS after " */": expected "", was ""
  (in /var/app/current/app/assets/stylesheets/application.css)
(sass):13506

我的设置如下:

64bit Amazon Linux 2014.03 v1.0.4 running Ruby 2.0 (Passenger Standalone)
Rails 4.1.1
Postgresql

更新 1: 这是我的application.css。它只是rails附带的默认设置

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 */

我还忘记了一件大事。我在 production.log No route matches [GET] "/stylesheets/application.css"

中收到此错误
F, [2014-07-04T20:25:02.034054 #29628] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'
  passenger (4.0.45) lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
  passenger (4.0.45) lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
  passenger (4.0.45) lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
  passenger (4.0.45) lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'

【问题讨论】:

这与Passenger或EB无关,这完全取决于您的CSS资产无法编译。从记忆中,我认为 EB 将在您部署新版本时运行 rake assets:precompile 任务,如果这不起作用,那么将没有资产可供服务。您看到的错误表明您的 application.css 文件中存在错误,您可以发布内容以便我们查看可能出现的问题吗? 是的对不起,我添加了 CSS 和 production.log 错误。 【参考方案1】:

哦,天哪。这是我自己的错。 Paul Leader 是对的,这与乘客无关。问题是我的一个文件在另一个 css 文件中有一些额外的字符:>>>>>>>>>>>>>>>>>>>External Changes,这是因为我使用了两个相互冲突的文本编辑器。'

糟糕的是,我希望错误没有显示 application.css,而是显示导致问题的实际文件。

啊!!!!!!!!!

【讨论】:

以上是关于Elastic Beanstalk Passenger-Standalone Rails 不提供静态资产的主要内容,如果未能解决你的问题,请参考以下文章

elastic-beanstalk http请求超时

在 AWS Elastic Beanstalk 和 EKS 上部署了一个 laravel 应用程序 相同的数据库 RDS 为啥在 Elastic Beanstalk 中获得快速响应

AWS Elastic Beanstalk CLI 安装错误

text codepipeline + Elastic Beanstalk

text AWS Elastic Beanstalk

[AWS] Elastic Beanstalk