50

I'd like to add a few extra types to nginx mime types, but I don't want to edit the default /etc/nginx/mime.types as it would add some extra complexity to the deployment process.

If I add a types {...} section to my nginx.conf it will override all the other types that were declared with the include mime.types;.

I've thought that I could write a location rule for the extensions of the files that I need to handle, but I suppose that there must be a cleaner way to achieve this.

guruz
  • 1,604
  • 14
  • 21
fortran
  • 74,053
  • 25
  • 135
  • 175

1 Answers1

88

If I add a types {...} section to my nginx.conf it will override all the other types that were declared with the include mime.types;.

No, it won't.

You just need to specify additional types on the same level as your mime.types include:

include mime.types;
types {
    # here are additional types
    application/javascript mjs;
}
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
VBart
  • 14,714
  • 4
  • 45
  • 49
  • 5
    only if the include and types are in the same `scope` – gdamjan Jan 18 '16 at 18:46
  • it works with the "include /etc/nginx/mime.types;" instead of "include mime.types;" and adding of course the extra types "types { # here are additional types application/javascript mjs; }" – Gerard_dev Sep 21 '22 at 15:10