Webpacker: Right way to serve pack files in production?

Created on 17 Apr 2017  路  9Comments  路  Source: rails/webpacker

I have some confusion about what is the right way to serve pack files in production. I am on elastic beanstalk. In my production.rb I can see this lines:

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

Should I use this or configure nginx to handle this for me?

Here is something I plan to do:

location /packs {
  root /var/app/current/public/packs;
}

Can you point this in the right direction?

Most helpful comment

Sorry all for the delay I figured this out a day back. I read at lot of different places and someone provided me with a starters script which I have modified and it works:

This is the gist https://gist.github.com/ankitsinghaniyaz/48b3276d344668dff82a2b1cc3a8d455

some one has also suggested me to use:

location / {
  root /var/app/current/public;
}

and says that should be sufficient but I still have to try that. I hope this helps! Also now I serve all my assets via nginx.

All 9 comments

@ankitsinghaniyaz You are already in right direction 馃槃

Here is an example app that uses cloudfront - https://webpacker-example-app.herokuapp.com/

With nginx as proxy it will handle serving static files automatically so, don't think you need to configure anything on nginx side. You can unset RAILS_SERVE_STATIC_FILES(if already set) when using nginx.

@gauravtiwari actually I deployed the same app to Heroku and it worked fine, but unable to do the same on EB.

Hmm, right. Do you get any errors? I guess it's just matter of pointing cloudfront to the public directory. For nginx, I think this should work out-of-the-box.

I have a hunch that this has to do with how you configure your CDN in production and staging. I will report back here with findings.

@ankitsinghaniyaz Were you able to figure this out?

Sorry all for the delay I figured this out a day back. I read at lot of different places and someone provided me with a starters script which I have modified and it works:

This is the gist https://gist.github.com/ankitsinghaniyaz/48b3276d344668dff82a2b1cc3a8d455

some one has also suggested me to use:

location / {
  root /var/app/current/public;
}

and says that should be sufficient but I still have to try that. I hope this helps! Also now I serve all my assets via nginx.

Great, thanks for sharing. I think that should be enough. Alright closing this one then 馃檪

Was this page helpful?
0 / 5 - 0 ratings