首页 文章

如何在Elastic Beanstalk容器中提供Rails应用程序的webpacked资产?

提问于
浏览
2

我正在使用Rails5应用程序并成功将其部署到EB容器 .

但webpacked资产 - 直接在 public/packs 中提供,在 生产环境 环境中返回404 .

在目前的情况下,我设置 RAILS_SKIP_ASSET_COMPILATION = false 所以我在每次部署应用程序之前预编译资产 .

我过去常常使用heroku作为 生产环境 环境,当时一切正常 .

这是我的 config/webpacker.yml

source_path: app/frontend/javascripts
  source_entry_path: packs
  public_output_path: packs # public/packs/filename-[hash].js
  cache_path: tmp/cache/webpacker

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:
    - .js
    - .sass
    - .scss
    - .css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

我试过的......

我试图将public_output_path从包更改为资产 . 但同样的错误仍然存在......

1 回答

  • 0

    我也遇到了这个问题 . 我'm not sure if you'重新使用Nginx或Passenger . 但如果它's Nginx you' ll可能想要添加一个如下所示的 /etc/nginx/conf.d/webapp_healthd.conf 的位置块:

    location /packs {
      alias /var/app/current/public/packs;
      gzip_static on;
      gzip on;
      expires max;
      add_header Cache-Control public;
    }
    

    然后运行 sudo /etc/init.d/nginx restart .

    这应该足以让它运作起来 . 但是您需要使用这些自定义设置在项目中创建 .ebextensions/ 文件,以免被Elastic Beanstalk默认配置覆盖 .

相关问题