Skip to content

Instantly share code, notes, and snippets.

@vochicong
Created February 12, 2018 08:17
Show Gist options
  • Select an option

  • Save vochicong/3d0b7c8ec8d3cb061efce7f8473caa48 to your computer and use it in GitHub Desktop.

Select an option

Save vochicong/3d0b7c8ec8d3cb061efce7f8473caa48 to your computer and use it in GitHub Desktop.
EB setting to make nginx look at assets in public/packs
# .ebextensions/25_nginx.config
# By default, Webpacker/Rails will compile assets into public/packs,
# but nginx by EB default settings doesn't look at that folder.
files:
"/etc/nginx/conf.d/rails-webpack.conf" :
# Modified from /etc/nginx/conf.d/webapp_healthd.conf
mode: "000644"
owner: root
group: root
content: |
upstream my_app {
server unix:///var/run/puma/my_app.sock;
}
log_format healthd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
server_name _ localhost; # need to listen to localhost for worker tier
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
location / {
proxy_pass http://my_app; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /assets {
alias /var/app/current/public/assets;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
# This block is for webpack --START--
location /packs {
alias /var/app/current/public/packs;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
# This block is for webpack --END--
location /public {
alias /var/app/current/public;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
}
commands:
10_rm_nginx_default_webapp_conf:
command: |
mv /etc/nginx/conf.d/webapp_healthd.conf \
/etc/nginx/conf.d/webapp_healthd.conf.bak
test: "[ -f /etc/nginx/conf.d/webapp_healthd.conf ]"
services:
sysvinit:
nginx:
enabled: true
ensureRunning: true
files:
- "/etc/nginx/conf.d/rails-webpack.conf"
commands:
- "10_rm_nginx_default_webapp_conf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment