0

New to nginx. I searched for this but was unable to find what I was looking for, maybe I'm thinking of it wrong.

Is there a way to add the following rules to an nginx conf somewhere which will apply to any new domains added to the install w/o having to add the rules to each new domain's conf?

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html|xml|json)$ {
  expires -1;
#  access_log logs/static.log;
}

# Feed
location ~* \.(?:rss|atom)$ {
  expires 1h;
  add_header Cache-Control "public";
}

# Favicon
location ~* \.ico$ {
  expires 1w;
  access_log off;
  add_header Pragma public;
  add_header Cache-Control "public";
}

# Media: images, video, audio, HTC, WebFonts
location ~* \.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
  expires 1M;
  access_log off;
  add_header Pragma public;
  add_header Cache-Control "public";
}

location ~* \.(js|css)$ {
  expires 60d;
  add_header Pragma public;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
}

# opt-in to the future
add_header "X-UA-Compatible" "IE=Edge,chrome=1";

Thanks.

Steve Adams
  • 101
  • 2

1 Answers1

1

Put the configuration you posted here into an separate file (e.g. /etc/nginx/conf.d/expires.global) and then include that file in your virtualhosts using include directive.

server {
  ...
  include /etc/nginx/conf.d/expires.global;
}
Tubeless
  • 1,492
  • 13
  • 15